note 82283 added to function.array-search

From: Date: Fri, 04 Apr 2008 00:07:52 +0000
Subject: note 82283 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-137910@lists.php.net to get a copy of this message
Combining syntax of array_search() and functionality of array_keys() to get all key=>value associations of an array with the given search-value: <?php function array_search_values( $m_needle, $a_haystack, $b_strict = false){ return array_intersect_key( $a_haystack, array_flip( array_keys( $a_haystack, $m_needle, $b_strict))); } ?> Usage: <?php $array1 = array( 'pre'=>'2', 1, 2, 3, '1', '2', '3', 'post'=>2); print_r( array_search_values( '2', $array1)); print_r( array_search_values( '2', $array1, true)); print_r( array_search_values( 2, $array1, true)); ?> Will return: array(4) { ["pre"] => string(1) "2" [1] => int(2) [4] => string(1) "2" ["post"] => int(2) } array(2) { ["pre"] => string(1) "2" [4] => string(1) "2" } array(2) { [1] => int(2) ["post"] => int(2) } ---- Server IP: 217.13.201.10 Probable Submitter: 85.180.24.112 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/82283 Del: integrated -- https://master.php.net/note/delete/82283/integrated Del: useless -- https://master.php.net/note/delete/82283/useless Del: bad code -- https://master.php.net/note/delete/82283/bad+code Del: spam -- https://master.php.net/note/delete/82283/spam Del: non-english -- https://master.php.net/note/delete/82283/non-english Del: in docs -- https://master.php.net/note/delete/82283/in+docs Del: other reasons-- https://master.php.net/note/delete/82283 Reject -- https://master.php.net/note/reject/82283 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137910) next »