all I need to understand is why I always get generated array having 0 index if I declare the value I want I want this output
Array
(
[0] => Array
(
[label] => Prima categoria,
[url] => Array
(
[0] => categorie/prima-categoria
)
)
[1] => Array
(
[label] => Seconda
[url] => Array
(
[0] => categorie/seconda
)
[items] => Array
(
[label] => Seconda
[url] => Array
(
[0] => categorie/seconda
)
)
)
)
but now:
Array
(
[0] => Array
(
[label] => Prima categoria,
[url] => Array
(
[0] => categorie/prima-categoria
)
)
[1] => Array
(
[label] => Seconda
[url] => Array
(
[0] => categorie/seconda
)
// this is the problem --- why 0??
[0] => Array
(
[items] => Array
(
[label] => Seconda
[url] => Array
(
[0] => categorie/seconda
)
)
)
)
)
the function I am trying to implement
function getItems() {
$items = [];
foreach (getLabelName() as $key) {
$url = str_replace(' ', '-', $key->name);
$subMenu = [];
if (isset($key->id_sub_cat)) {
$subMenu['items'] = ['label' => ucfirst($key->name), 'url' => ['category/' . $url . '']];
}
$items[] = ['label' => ucfirst($key->name), 'url' => ['category/' . $url . ''], $subMenu];
}
return $items;
}
Hope you understand my explanation.