3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $regions = array(); $regions[65] = array('id' => 65, 'parent_id' => 44, 'name' => "Shoreditch"); $regions[77] = array('id' => 77, 'parent_id' => 5, 'name' => "England"); $regions[100] = array('id' => 100, 'parent_id' => 0, 'name' => "Europe"); $regions[5] = array('id' => 5, 'parent_id' => 100, 'name' => "United Kingdom"); $regions[44] = array('id' => 44, 'parent_id' => 77, 'name' => "London"); $hierarchy = array(); function get_hierarchy($regions, $region_id = 0) { if (0 === $regions[$region_id]['parent_id']) { return $regions[$region_id]['name']; } else { get_hierarchy($regions, $regions[$region_id]['parent_id']); } return $regions[$region_id]['name']; } var_dump(get_hierarchy($regions, 44));
based on 6jk7s
Output for 4.3.0 - 7.2.0
string(6) "London"