note 36907 deleted from function.in-array by danbrown

From: Date: Mon, 08 Jun 2009 21:46:34 +0000
Subject: note 36907 deleted from function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156526@lists.php.net to get a copy of this message
Note Submitter: michi at F*CKSPAM michianimations dot de ---- This is another solution to multi array search. It works with any kind of array, also privides to look up the keys instead of the values - $s_key has to be 'true' to do that - and a optional 'bugfix' for a PHP property: keys, that are strings but only contain numbers are automatically transformed to integers, which can be partially bypassed by the last paramter. function multi_array_search($needle, $haystack, $strict = false, $s_key = false, $bugfix = false){ foreach($haystack as $key => $value){ if($s_key) $check = $key; else $check = $value; if(is_array($value) && multi_array_search($needle, $value, $strict, $s_key) || ( $check == $needle && ( !$strict || gettype($check) == gettype($needle) || $bugfix && $s_key && gettype($key) == 'integer' && gettype($needle) == 'string' ) ) ) return true; } return false; }

« previous php.notes (#156526) next »