$find = 13;$path = array();function FindById ($arr, $find) { $k = null; foreach($arr as $key => $item) if ($item['id'] == $find) { $k = $key; break; } return $k;}if ( false === ($k = FindById($arr, $find))) die("not found");while (true) { array_unshift($path, $arr[$k]['name']); if( ! $arr[$k]['parent']) break; if(false === ($k = FindById($arr, $arr[$k]['parent']))) die("illegal structure");} echo implode('->', $path);
↧
Answer by splash58 for Get path from adjacency list data
↧
Trending Articles
More Pages to Explore .....