note 20594 added to function.in-array

From: Date: Tue, 09 Apr 2002 12:53:10 +0000
Subject: note 20594 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-29008@lists.php.net to get a copy of this message
If you want to search a multiple array for a value - you can use this function - which looks up the value in any of the arrays dimensions (like in_array() does in the first dimension). Note that the speed is growing proportional with the size of the array - why in_array is best if you can determine where to look for the value. Copy & paste this into your code... function in_multi_array($needle, $haystack) { $in_multi_array = false; if(in_array($needle, $haystack)) { $in_multi_array = true; } else { for($i = 0; $i < sizeof($haystack); $i++) { if(is_array($haystack[$i])) { if(in_multi_array($needle, $haystack[$i])) { $in_multi_array = true; break; } } } } return $in_multi_array; } -- http://www.php.net/manual/en/function.in-array.php http://master.php.net/manage/user-notes.php?action=edit+20594 http://master.php.net/manage/user-notes.php?action=delete+20594 http://master.php.net/manage/user-notes.php?action=reject+20594

« previous php.notes (#29008) next »