Quantcast
Channel: Get path from adjacency list data - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by splash58 for Get path from adjacency list data

$
0
0
$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);

Viewing all articles
Browse latest Browse all 4




<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>