note 84396 added to function.in-array

From: Date: Sat, 12 Jul 2008 10:47:33 +0000
Subject: note 84396 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-141421@lists.php.net to get a copy of this message
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. ---- Server IP: 217.13.201.10 Probable Submitter: 91.20.123.170 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/84396 Del: integrated -- https://master.php.net/note/delete/84396/integrated Del: useless -- https://master.php.net/note/delete/84396/useless Del: bad code -- https://master.php.net/note/delete/84396/bad+code Del: spam -- https://master.php.net/note/delete/84396/spam Del: non-english -- https://master.php.net/note/delete/84396/non-english Del: in docs -- https://master.php.net/note/delete/84396/in+docs Del: other reasons-- https://master.php.net/note/delete/84396 Reject -- https://master.php.net/note/reject/84396 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141421) next »