| cID | cPID | cSlug | cName | 
|---|---|---|---|
| 1 | 0 | hello | H1 | 
| 2 | 0 | world | WORLD | 
| 3 | 0 | mars | MARS | 
| 4 | 1 | people | People | 
| 5 | 1 | dogs | Dogs | 
| 6 | 3 | cats | Cats:) | 
cPID: Parent ID
PHP:
$getMenuData = $db->table($vtCategories)->getAll();
$menu = [];
foreach ($getMenuData as $row) {
    if ($row->cPID === 0) {
        $menu[$row->cID] = $row;
        $menu[$row->cID]['submenus'] = [];
    } else {
        $menu[$row->cPID]['submenus'][] = $row;
    }
}
foreach ($menu as $item) {
    echo $item->cID . '<br>' . PHP_EOL;    //  <<--- LINE 16
    foreach ($item['submenus'] as $subitem) {
        echo '<br>' . $subitem->cName . '--' . $subitem->cPID . PHP_EOL;
    }
}
I get this error:
Notice: Trying to get property 'cID' of non-object in /var/www/clients/client7/web31/web/test1.php on line 16
Where am I doing wrong?
