So, I was trying to print my class:
class category {
public $name;
public $id;
public $subCats = array();
public function __construct($name = "", $id = "") {
$this->name = $name;
$this->id = $id;
}
public function add_sub_cat($subCat) {
array_push($this->subCats, $subCat);
}
}
In two ways recursive and iterative, first one I did without any problems:
function recursive_print($category, $path) {
?>
<li><div id="category-name" ><p><? echo $category->name ?></p>
</div></li>
<?php foreach($category->subCats as $subCat) { ?>
<ul>
<?php recursive_print($subCat, $path.=$subCat->id) ?>
</ul>
<?php }
}
But now I got stuck on second part of this task. Do I have to modify my class? Is it even possible to print without recursion? I have read this but it did not cleared anything. Maybe someone have better tutorial or any advice?