note 84396 deleted from function.in-array by danbrown

From: Date: Mon, 08 Jun 2009 21:40:26 +0000
Subject: note 84396 deleted from function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156497@lists.php.net to get a copy of this message
Note Submitter: Gary Luck ---- function to check a multidimensional array if a given array is in the "haystack". <? $Example_Needle['Art'] = 'Verb'; $Example_Needle['Verbform']['Finitiv'] = 1; $Example_Haystack[5] = 2; $Example_Haystack[7] = 'nein'; $Example_Haystack['ID'] = 1; $Example_Haystack['Art'] = 'Verb'; $Example_Haystack['Verbform']['Finitiv'] = 1; $Example_Haystack['Zeitform']['Präsens'] = 'ja'; function is_in_array($Needle, $Haystack){ reset($Needle); while(list($Key, $Value) = each($Needle)){ if(!array_key_exists($Key, $Haystack)){ return false; } if(!is_array($Value)){ if(in_array($Value, $Haystack)){ $Return = true; }else{ return false; } }else{ if(is_in_array($Value, $Haystack[$Key])){ $Return = true; }else{ return false; } } } return $Return; } if(is_in_array($Example_Needle, $Example_Haystack)){ echo 'yes'; }else{ echo 'no'; } ?> This will emit "yes". The given needle must be an array. A string as the needle is not supported in this function.

« previous php.notes (#156497) next »