note 20594 deleted from function.in-array by googleguy

From: Date: Tue, 22 Oct 2013 09:01:26 +0000
Subject: note 20594 deleted from function.in-array by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196829@lists.php.net to get a copy of this message
Note Submitter: jon at gaarsmand dot dk ---- 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... <?php 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; } ?>

« previous php.notes (#196829) next »