note 84073 deleted from function.array-map by cmb
| From: | cmb@php.net | Date: | Sun, 29 Dec 2019 10:33:13 +0000 |
| Subject: | note 84073 deleted from function.array-map by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213688@lists.php.net to get a copy of this message | ||
Note Submitter: GUI
----
The following takes an array of objects, and returns the result of calling a member function on each
object. So if I have an array of objects that all have a getName() method, calling
array_map_objects("getName", $thingies) will return the array filled with the getName()
value for each object.
<?php
function array_map_objects($member_function, $array) {
$values = array();
if(is_string($member_function) && is_array($array)) {
$callback = create_function('$e', 'return call_user_func(array($e, "' .
$member_function .'"));');
$values = array_map($callback, $array);
}
return $values;
}
?>