我有此数组:array_filter()返回一个空数组
array
0 => string 'http://example.com/site.xml'
1 => string 'http://example.com/my_custom_links_part1.xml'
2 => string 'http://example.com/my_custom_links_part2.xml'
3 => string 'http://example.com/my_custom_links_part3.xml'
4 => string 'http://example.com/my_some_other_custom_links_part1.xml'
这个代码来获取的名称中包含 “my_custom_links”(而不是 “my_come_other_custom_links”)
<?php
$matches = array_filter($urls, function($var) { return preg_match("/^my_custom_links$/", $var); });
echo "<pre>";
print_r($urls); // will output all links
echo "</pre>";
echo "<pre>";
print_r($matches); // will output an empty array
echo "</pre>";
?>
链接
我应该得到一个有3个项目的数组,但我得到一个空数组。