进行一些粗略的递归,但应该可以:
function find_parent($array, $needle, $parent = null) { foreach ($array as $key => $value) { if (is_array($value)) { $pass = $parent; if (is_string($key)) { $pass = $key; } $found = find_parent($value, $needle, $pass); if ($found !== false) { return $found; } } else if ($key === 'id' && $value === $needle) { return $parent; } } return false;}$parentkey = find_parent($array, '0002');
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)