I am slightly confused how do I refactor to return array data instead storing $this->data
in the makeData()
method.
For example:
private function makeData($cat, $itemCatId)
{
$parentCat = $cat[$cat[$itemCatId]->parent_id];
$this->data[] = $parentCat;
if (!is_null($parentCat->parent_id)) {
$this->makeData($cat, $parentCat->id);
}
}
Usage
foreach($items as $item) {
$this->data = []
$this->makeData($cat, $item->id);
// Then do something with `$this->data`
}
Then do something with $this->data
It seem this look like a code smell, in there a way to return data from makeData()
when the Recursive is completed? For example:
foreach($items as $item) {
$data = $this->makeData($cat, $item->id);
// Then do something with `$data`
}