note 36907 added to function.in-array

From: Date: Sun, 26 Oct 2003 21:47:04 +0000
Subject: note 36907 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-59349@lists.php.net to get a copy of this message
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; } ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36907 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36907&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36907&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59349) next »