<?php Id | name | parent_id 1 | A | Null 2 | b | 1 3 | c | 2 4 | d | 3 5 | e | 4 6 | f | 5 7 | g | 6 8 | h | 7 9 | i | 8 10 | j | 9 if(count($parentCats) >0 ) { foreach($parentCats as $cat) { // if($cat->parent_id) // { // $newCats = Categories::ById($cat->parent_id)->get(); // if(count($parentCats)) // array_push($datas) // } if($cat->parent_id) { while(count($subcats = Categories::ById($cat->parent_id)->get()) > 0) { foreach($cat) } } // while() array_push($datas,$cat); } return $datas; } return false; ?>