...

View Full Version : Resolved If inside multi array, return array



RonnyNishimoto
07-29-2012, 06:52 AM
I'm using:



function in_array_multi($needle, $haystack) {
foreach ($haystack as $item) {
if ($item === $needle || (is_array($item) && in_array_multi($needle, $item))) {
return true;
}
}
return false;
}


If the needle is in the 2nd array, return the name of the array.
IE:

$candy = array("chocolate" => array("snicker","musketeer"));

if musketeer is found, return chocolate

How can I do this? If not possible, how with just an associative array?

RonnyNishimoto
07-29-2012, 09:15 AM
I figured it out:



if (array_search($v, $array) == true) { // $v in associative
$draft = array_search($v, $array);
}
foreach ($array2 as $key => $value) { // $v in multi-dimensional
if (in_array($v, $value)) {
$v = $key;
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum