PHP Return array from recursive function -
when echo out $value['id']. $value['label']; every row echoed out //that's want. but, when return $result first array returned.. how can fix this?
here's code:
public function recursive_category($tree,$indent=0) { $indent++; // try depth of current array foreach ($tree $value) { foreach ($value $key => $value) { $indent_str = str_repeat("--", $indent); echo $value['id'].' '.$value['label'].'<br>'; $id[] = $value['id']; $label[] = $value['label']; if (!empty($value['items'])) { self::recursive_category($value['items'],$indent); } }; } $result = array_combine($id, $label); return $result; }
Comments
Post a Comment