note 84073 added to function.array-map
| From: | GUI at osu1 dot php dot net | Date: | Thu, 26 Jun 2008 14:48:36 +0000 |
| Subject: | note 84073 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140836@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 192.174.37.50
----
Manual Page -- http://www.php.net/manual/en/function.array-map.php
Edit -- https://master.php.net/note/edit/84073
Del: integrated -- https://master.php.net/note/delete/84073/integrated
Del: useless -- https://master.php.net/note/delete/84073/useless
Del: bad code -- https://master.php.net/note/delete/84073/bad+code
Del: spam -- https://master.php.net/note/delete/84073/spam
Del: non-english -- https://master.php.net/note/delete/84073/non-english
Del: in docs -- https://master.php.net/note/delete/84073/in+docs
Del: other reasons-- https://master.php.net/note/delete/84073
Reject -- https://master.php.net/note/reject/84073
Search -- https://master.php.net/manage/user-notes.php