3v4l.org

run code in 300+ PHP versions simultaneously
<?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); } } } ?>

preferences:
25.17 ms | 404 KiB | 5 Q