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

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -