Example
http://www.lornajane.net/posts/2012/php-recursive-function-example-factorial-numbers
Get leaf nodes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//Get all cat id of leaf certificate categories function get_leaf_cats($parent=54, $arr=array(), $traverse=true){ $cats = $this->get_children($parent); if($cats == false){ array_push($arr, $parent); return $arr; }else{ foreach($cats as $item){ $arr = $this->get_leaf_cats($item['id'], $arr); } return $arr; } } |