function getpath($id, $arr, $level = 0) { $result = array(); foreach($arr as $key => $value){ if($id == $value['id']){ $result[] = $value['name']; $id = $value['parent']; if($id != 0){ $result = array_merge($result, getpath($id, $arr, $level+1)); }else{ break; } } } return $level ? $result : implode('->',array_reverse($result));}echo getpath(13,$arr);
↧
Answer by Narendrasingh Sisodia for Get path from adjacency list data
↧