Re: Performance question about create_function
| From: | Mathieu Suen | Date: | Mon, 26 Oct 2009 14:25:21 +0000 |
| Subject: | Re: Performance question about create_function | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-45881@lists.php.net to get a copy of this message | ||
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.suen@easyflirt.com> wrote:-- -- Mathieu Suen --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) {I think what you want to do can be done with anonymous functions:$ids[] = $someInstances->getId();}$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