从通配符中删除php数组中的特定键
问题描述:
我正在尝试搜索特定部分字符串的数组并删除所有包含它们的键。我已经试过几件事情,我的PHP-FU在这里不多了......从通配符中删除php数组中的特定键
数组我正在寻找(部分,但沿着这些线路多)是这样的:
Array
(
[0] => /.
[1] => /..
[2] => /htdocs
[3] => /htdocs/.
[4] => /htdocs/..
[5] => /htdocs/zipper_new.php
[6] => /htdocs/bottom.gif
)
我试图删除所有包含“/”的条目和“/ ..”。
它的长短是我做了一个脚本来搜索文件的文件类型和tar他们,我想添加功能,而不是搜索所有的文件,并做同样的事情,这部分是失败援引包含整个或部分字符串的条目。
答
$data = array(
'/.',
'/..',
'/htdocs',
'/htdocs/.',
'/htdocs/..',
'/htdocs/zipper_new.php',
'/htdocs/bottom.gif',
);
$match = '/.';
$newData = array_filter(
$data,
function($value) use ($match) {
return (!fnmatch('*' . $match . '*', $value));
}
);
var_dump($newData);
我曾试图array_filter(),但看来我绝对没有使用正确的方式:)感谢这么多! –