note 87579 added to function.array-search

From: Date: Thu, 11 Dec 2008 11:32:47 +0000
Subject: note 87579 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-148024@lists.php.net to get a copy of this message
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 ;) ---- Server IP: 213.249.64.162 Probable Submitter: 62.132.177.129 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/87579 Del: integrated -- https://master.php.net/note/delete/87579/integrated Del: useless -- https://master.php.net/note/delete/87579/useless Del: bad code -- https://master.php.net/note/delete/87579/bad+code Del: spam -- https://master.php.net/note/delete/87579/spam Del: non-english -- https://master.php.net/note/delete/87579/non-english Del: in docs -- https://master.php.net/note/delete/87579/in+docs Del: other reasons-- https://master.php.net/note/delete/87579 Reject -- https://master.php.net/note/reject/87579 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148024) next »