note 87579 deleted from function.array-search by levim

From: Date: Mon, 24 Feb 2014 22:42:41 +0000
Subject: note 87579 deleted from function.array-search by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198655@lists.php.net to get a copy of this message
Note Submitter: grezvany13 [at] notitia.nl ---- This function can search for an array or string within an array. <?php function array_search_array($needle, $haystack){ if(is_array($needle) && is_array($haystack)) { $tmp = array_diff_assoc($needle, $haystack); if(empty($tmp)) return true; foreach($haystack as $value) { if(is_array($value)) { $tmp = array_diff_assoc($needle, $value); if(empty($tmp)) return true; } } } if(is_array($haystack) && !is_array($needle)) { foreach($haystack as $value) { if(is_array($value)) { $tmp = array_diff_assoc($needle, $value); if(empty($tmp)) return true; } elseif($needle == $value) return true; } } elseif($needle == $haystack) return true; return false; } ?> It's not recursive yet, so please improve it if you feel for it ;)

« previous php.notes (#198655) next »