Yes that the same but only for PHP <= 5.3.
I am more asking about performance.
Michael Stillwell a écrit :
On Mon, Oct 19, 2009 at 1:13 PM, Mathieu Suen
<mathieu.s...@easyflirt.com> wrote:
Looking at the way array_map is working, it could worth to use
create_function for object.
For example if I got a list of object:
$callback = create_function($element, 'return $selement->getId();');
$ids = array_map($callback, $someInstances);
But I don't know if it's cost a lot in performance instead of the ugly
verbose way:
$ids = array();
foreach($someInstances)
{
$ids[] = $someInstances->getId();
}
I think what you want to do can be done with anonymous functions:
$arr1 = array(
(object) array("id" => 56),
(object) array("id" => 42)
);
$ids = array_map(function($obj) { return $obj->id; }, $arr1);
print_r($ids);
produces:
Array
(
[0] => 56
[1] => 42
)
Michael
--
-- Mathieu Suen
--
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php