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); } } } ?>
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
<a href="mypage.php?id=2&dir=fred"><li>fred</li></a><a href="mypage.php?id=2&dir=sam"><li>sam</li></a><a href="mypage.php?id=2&dir=alan"><li>alan</li></a><a href="mypage.php?id=2&dir=john"><li>john</li></a>

preferences:
141.96 ms | 408 KiB | 5 Q