note 94859 deleted from function.in-array by bjori

From: Date: Fri, 01 Jan 2010 17:33:33 +0000
Subject: note 94859 deleted from function.in-array by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164517@lists.php.net to get a copy of this message
Note Submitter: joe at kobo dot com dot au ---- I wanted a function where I could check to see if any or all of the needles of one array were in another array. So I wrote this function based on some functions here: <?php // array has matches - used to check if one array holds data that is in the other array function array_match($needle, $haystack, $match_all = false) { $all_matched = true; // loop through the needles foreach((array)$needle AS $pin) { if(in_array($pin, $haystack)) { if($match_all === false) { return true; } } else { if($match_all === true) { return false; } } } if($match_all === true) { return true; } else { return false; } } ?> The $match_all flag allows you to check if all values are within the other array or not if set to true, otherwise any one match will return true.

« previous php.notes (#164517) next »