I have used the function below and the output is not quite what I was expecting. The output is, what am I doing wrong here??
Array
(
[0] => Array
(
[2] => Green-Green
)
)
multiArrayValueSearch($key4, 'Green-Green', $t);
print_r($t);
function multiArrayValueSearch($haystack, $needle, &$result, &$aryPath=NULL, $currentKey='') {
if (is_array($haystack)) {
$count = count($haystack);
$iterator = 0;
foreach($haystack as $location => $straw) {
$iterator++;
$next = ($iterator == $count)?false:true;
if (is_array($straw)) $aryPath[$location] = $location;
multiArrayValueSearch($straw,$needle,$result,$aryPath,$location);
if (!$next) {
unset($aryPath[$currentKey]);
}
}
} else {
$straw = $haystack;
if ($straw == $needle) {
if (!isset($aryPath)) {
$strPath = "\$result[$currentKey] = \$needle;";
} else {
$strPath = "\$result['".join("']['",$aryPath)."'][$currentKey] = \$needle;";
}
eval($strPath);
}
}
}
Expected results is :
Array
(
[0] => Array
(
[0] => 1
[1] => 144
[2] => Green-Green
)
)