note 94859 added to function.in-array

From: Date: Sun, 29 Nov 2009 13:40:38 +0000
Subject: note 94859 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-163372@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 121.50.215.195 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/94859 Del: integrated -- https://master.php.net/note/delete/94859/integrated Del: useless -- https://master.php.net/note/delete/94859/useless Del: bad code -- https://master.php.net/note/delete/94859/bad+code Del: spam -- https://master.php.net/note/delete/94859/spam Del: non-english -- https://master.php.net/note/delete/94859/non-english Del: in docs -- https://master.php.net/note/delete/94859/in+docs Del: other reasons-- https://master.php.net/note/delete/94859 Reject -- https://master.php.net/note/reject/94859 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163372) next »