note 113795 added to function.array-map

From: Date: Tue, 03 Dec 2013 10:55:41 +0000
Subject: note 113795 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-197728@lists.php.net to get a copy of this message
Let's assume we have following situation: <?php class MyFilterClass { public function filter(array $arr) { return array_map(function($value) { return $this->privateFilterMethod($value); }); } private function privateFilterMethod($value) { if (is_numeric($value)) $value++; else $value .= '.'; } } ?> This will work, because $this inside anonymous function (unlike for example javascript) is the instance of MyFilterClass inside which we called it. I hope this would be useful for anyone. ---- Server IP: 192.41.45.150 Probable Submitter: 87.105.187.246 ---- Manual Page -- http://php.net/manual/en/function.array-map.php Edit -- https://master.php.net/note/edit/113795 Del: integrated -- https://master.php.net/note/delete/113795/integrated Del: useless -- https://master.php.net/note/delete/113795/useless Del: bad code -- https://master.php.net/note/delete/113795/bad+code Del: spam -- https://master.php.net/note/delete/113795/spam Del: non-english -- https://master.php.net/note/delete/113795/non-english Del: in docs -- https://master.php.net/note/delete/113795/in+docs Del: other reasons-- https://master.php.net/note/delete/113795 Reject -- https://master.php.net/note/reject/113795 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197728) next »