PHP array_filter with get_class filter -


i have array of objects, , want check if classname in it. tried:

$all_classnames = array_filter($obj_array, 'get_class'); $found = in_array("classname_to_test", $all_classnames); 

only, $all_classnames still holds original object array instead of array of classnames (through get_class). missing here?

you want use array_map (which transforms input array based on callback function) instead of array_filter:

$all_classnames = array_map('get_class', $obj_array); 

note array_map takes arguments in reverse order other array functions use callback because php.


Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -