<?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));
- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- string(6) "London"
preferences:
213.41 ms | 406 KiB | 312 Q