How can I achieve this behavior?? I've tried to write a function to implement this logic, but for some reason it does not work. Here is the link that I tried to do http://sandbox.onlinephpfunctions.com/code/638fc7796a8918e2b7ef1469b746c29adba8d0cd
<?php
$test = [
'deepLink' => [
1,2,3,4,5, 'testMe'
],
'base' => [ // child for (2 and target)
'SuperMan',
'deepLink' // expected true, if we call array_search_for_target_key($test, 'target', 'testMe')
],
2 => [
'base' // link on child (base)
],
'target' => [
2 // link on child (2)
],
];
function array_search_for_target_key($array = array(), $targetKkey, $search) {
$res = false;
foreach($array as $k => $v) {
if ($k === $targetKkey && in_array($search, $v)) {
$res = true;
} else {
if (is_array($v)) {
foreach ($v as $nested) {
$array = $nested;
$res = array_search_for_target_key($array, $nested, $search);
}
}
}
}
return $res;
}
var_dump( array_search_for_target_key($test, 'target', 'SuperMan'));
So i soleved my problem, here the link