- array_keys: documentation ( source)
<?php
$arr = array("farm" =>
array("animals"=>
array("horses" =>
array("fred" => "fred",
"sam" => "sam",
"alan" => "alan",
"john" => "john")
)
)
);
$search = 'horses';
get_values($arr);
function get_values($arr){
global $search;
foreach($arr as $key => $value){
if($key == $search){
if(is_array($value)){
$keys = array_keys($value);
if(count($keys) > 1){
for($i = 0; $i < count($keys); $i++){
echo '<a href="mypage.php?id=2&dir='.$keys[$i].'"><li>'.$keys[$i].'</li></a>';
}
}else{
echo '<a href="mypage.php?id=2&dir='.$keys[0].'"><li>'.$keys[0].'</li></a>';
}
}
else{
echo $value;
}
}else{
get_values($value);
}
}
}
?>