我一直在调查array_map
但不确定这是否是最好的方法。
我目前从我的返回以下数组scandir
Array ( [0] => . [1] => .. [2] => .DS_Store [3] => post-my-first-test-post.html [4] => post-my-second-test-post.html )
我想删除数组中所有不匹配的项目"post-*
所以它只返回一个帖子数组。
我已经研究过使用glob
但不知道如何用我所拥有的来实现它。
就像是glob("post-*");
?
你应该看看数组过滤器() instead
$result = array_filter(
$originalArray,
function($value) {
return (strpos($value, 'post-') === 0);
}
);
虽然使用glob()而不是 scandir() 会允许您在实际检索目录列表时进行过滤
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)