note 54332 added to function.in-array

From: Date: Thu, 30 Jun 2005 16:24:34 +0000
Subject: note 54332 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-91214@lists.php.net to get a copy of this message
A foreach would be simpler for a multi-dimensional array search (and probably faster, since you an use the value instead of the index). Like this: <?PHP function in_multi_array($needle, $haystack) { $in_multi_array = false; if(in_array($needle, $haystack)) { $in_multi_array = true; } else { foreach $haystack as ($key => $val) { if(is_array($val)) { if(in_multi_array($needle, $val)) { $in_multi_array = true; break; } } } } return $in_multi_array; } ?> Using is_array($val) is probably faster than using is_array($haystack[$key]) ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54332 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54332&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54332&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54332&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54332&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54332&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54332&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54332&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91214) next »