note 117196 added to function.array-filter

From: Date: Thu, 30 Apr 2015 13:18:27 +0000
Subject: note 117196 added to function.array-filter
Groups: php.notes 
Request: Send a blank email to php-notes+get-202400@lists.php.net to get a copy of this message
If you have an array of KV pairs and you want all the items where a value is X, you dont need to make a callback for array_filter. You can use array_intersect: <?php print_r(array_intersect( array( 'a' => 1, 'b' => 1, 'c' => 1, 'd' => 2, 'e' => 2, 'f' => 2, ), array(1) )); Array ( [a] => 1 [b] => 1 [c] => 1 ) ?> The advantage of this approach is you can pass variables into the second array without needing to worry about variable scope and function parameters for array_filter. ---- Server IP: 72.52.91.14 Probable Submitter: 2.24.200.190 ---- Manual Page -- http://php.net/manual/en/function.array-filter.php Edit -- https://master.php.net/note/edit/117196 Del: integrated -- https://master.php.net/note/delete/117196/integrated Del: useless -- https://master.php.net/note/delete/117196/useless Del: bad code -- https://master.php.net/note/delete/117196/bad+code Del: spam -- https://master.php.net/note/delete/117196/spam Del: non-english -- https://master.php.net/note/delete/117196/non-english Del: in docs -- https://master.php.net/note/delete/117196/in+docs Del: other reasons-- https://master.php.net/note/delete/117196 Reject -- https://master.php.net/note/reject/117196 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202400) next »