function array_search_path($needle, array $haystack, array $path = []) {
foreach ($haystack as $key => $value) {
$currentPath = array_merge($path, [$key]);
if (is_array($value) && $result = array_search_path($needle, $value, $currentPath)) {
return $result;
} else if ($value === $needle) {
return $currentPath;
}
}
return false;
}
$arr = [
'foo' => 'bar',
'baz' => [
'test' => 42,
'here' => [
'is' => [
'the' => 'path'
]
],
'wrong' => 'turn'
]
];
print_r(array_search_path('path', $arr));
// Array
// (
// [0] => baz
// [1] => here
// [2] => is
// [3] => the
//)
"반환 값으로 처음 발견 된 값"중 하나를 선택하고 "반환"비즈니스를 제거하십시오. 어레이의 마지막을 칠 때까지 계속 검색하십시오. –
그리고 배열 구조는? –