gammaman Posted July 14, 2012 Share Posted July 14, 2012 I am trying to search a multi-dimentional array to see if it contains one or more values within another array. Here is the array I am trying to search. It is a from a function which returns an array of the meta data found in a specified website Array ( [title] => Video Games, Wikis, Cheats, Walkthroughs, Reviews, News & Videos - IGN [metaTags] => Array ( [description] => Array ( [html] => <meta name="description" content="IGN is your site for Xbox 360, PS3, Wii, PC, 3DS, PS Vita & iPhone games with expert reviews, news, previews, trailers, cheat codes, wiki guides & walkthroughs" /> [value] => IGN is your site for Xbox 360, PS3, Wii, PC, 3DS, PS Vita & iPhone games with expert reviews, news, previews, trailers, cheat codes, wiki guides & walkthroughs ) [robots] => Array ( [html] => <meta name="robots" content="noodp, noydir" /> [value] => noodp, noydir ) [copyright] => Array ( [html] => <meta name="copyright" content="IGN Entertainment, Inc." /> [value] => IGN Entertainment, Inc. ) ) ) Here is the function I am trying to use to do the search function recursive_array_search($needle,$haystack) { foreach($haystack as $key=>$value) { $current_key=$key; if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) { return true; } } return false; } Finally, here is the call to get the array of meta data, the array of search items to look for and the function call to the recursive_array_search $link = getBaseURL(); $metadata = getUrlData($link); // this function returns the array of all the meta-data $needle = array("PC","abc"); if(recursive_array_search($needle,$metadata) == true){ echo "VIOLATION"; } I want this to return true b/c at least one of the items in the search items array is found within the array of meta-data. Link to comment https://forums.phpfreaks.com/topic/265660-recursive-search-multi-dimentional-array/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.