There must be something I'm not understanding about array_filter in this context. I see plenty of mention of keys in the manual's user contents, but I'm not sure I'm understanding. The test array has "numeric" keys that are actually strings, true; but isn't array_filter checking the value? Can anyone explain why "unknown" is still in the post-filtered array?
(This has, apparently, not been a Good Week for my brain ... sorry).
[kadmin@freebsd-devel] $ cat test ; php test
<?php
function notUnknown($array_member) {
echo "checking for unknown, $array_member \n";
if (stristr($array_member,"unknown")) {
echo "Found string 'unknown'\n";
return false;
}
return true;
}
$test_array=array("1"=>234,"23"=>242,"250"=>'unknown',"345"=>122452);
echo "test array, pre-filter:\n";
print_r($test_array);
echo "filtering \n";
array_filter($test_array,"notUnknown");
echo "test array, post-filter:\n";
print_r($test_array);
test array, pre-filter:
Array
(
[1] => 234
[23] => 242
[250] => unknown
[345] => 122452
)
filtering
checking for unknown, 234
checking for unknown, 242
checking for unknown, unknown
Found string 'unknown'
checking for unknown, 122452
test array, post-filter:
Array
(
[1] => 234
[23] => 242
[250] => unknown
[345] => 122452
)