note 116553 added to function.array-filter

From: Date: Wed, 21 Jan 2015 22:32:40 +0000
Subject: note 116553 added to function.array-filter
Groups: php.notes 
Request: Send a blank email to php-notes+get-201490@lists.php.net to get a copy of this message
If you want to use array_filter with a class method as the callback, you can use a psuedo type callback like this: <?php class Test { public function doFilter($array) { return array_filter($array, array($this, 'callbackMethodName')); } protected function callbackMethodName($element) { return $element % 2 === 0; } } $example = new Test; print_r($example->doFilter(range(1, 10))); ?> Will return even numbers. ---- Server IP: 72.52.91.14 Probable Submitter: 203.167.134.229 ---- Manual Page -- http://php.net/manual/en/function.array-filter.php Edit -- https://master.php.net/note/edit/116553 Del: integrated -- https://master.php.net/note/delete/116553/integrated Del: useless -- https://master.php.net/note/delete/116553/useless Del: bad code -- https://master.php.net/note/delete/116553/bad+code Del: spam -- https://master.php.net/note/delete/116553/spam Del: non-english -- https://master.php.net/note/delete/116553/non-english Del: in docs -- https://master.php.net/note/delete/116553/in+docs Del: other reasons-- https://master.php.net/note/delete/116553 Reject -- https://master.php.net/note/reject/116553 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201490) next »