note 24082 added to function.in-array

From: Date: Tue, 06 Aug 2002 07:32:01 +0000
Subject: note 24082 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-34384@lists.php.net to get a copy of this message
In contribution of <jon@gaarsmand.dk>: I think we should use more general approach while walking through array, so instead your 'for' loop I'd suggest while list.. as follows: function in_multi_array($needle, $haystack) //taken from php.net, adapted { $in_multi_array = false; if(in_array($needle, $haystack)) { $in_multi_array = true; } else { while (list($tmpkey,$tmpval) = each ($haystack)) //here is the change { if(is_array($haystack[$tmpkey])){ if (in_multi_array($needle, $haystack[$tmpkey])) { $in_multi_array = true; break; } } } } return $in_multi_array; } I hope code is readible, some problems with formatting occured. -- http://www.php.net/manual/en/function.in-array.php http://master.php.net/manage/user-notes.php?action=edit+24082 http://master.php.net/manage/user-notes.php?action=delete+24082 http://master.php.net/manage/user-notes.php?action=reject+24082

« previous php.notes (#34384) next »