Recursive Function

Example

PHP Recursive Function Example: Factorial Numbers

Get leaf nodes:

//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;
	}
}