$arr = ['Массив' =>
[
'purchases' => 'Покупки',
'food' => 'Еда',
'vegetables' => 'Овощи',
'carrot' => 'Морковка',
]
];
[Массив] => Array
(
[purchases] => Покупки
[food] => Еда
[vegetables] => Овощи
[carrot] => Морковка
)
$arr = ['Массив' =>
[
'purchases' =>
[
'name' => 'Покупки',
'uri' => 'purchases'
],
'food' =>
[
'name' => 'Еда',
'uri' => 'purchases/food'
],
'vegetables' =>
[
'name' => 'Овощи',
'uri' => 'purchases/food/vegetables'
],
'carrot' =>
[
'name' => 'Морковка',
'uri' => 'purchases/food/vegetables/carrot'
]
]
];
[Массив] => Array
(
[purchases] => Array
(
[name] => Покупки
[uri] => purchases
)
[food] => Array
(
[name] => Еда
[uri] => purchases/food
)
[vegetables] => Array
(
[name] => Овощи
[uri] => purchases/food/vegetables
)
[carrot] => Array
(
[name] => Морковка
[uri] => purchases/food/vegetables/carrot
)
)
<?php
$arr = ['Массив' =>
[
'purchases' => 'Покупки',
'food' => 'Еда',
'vegetables' => 'Овощи',
'carrot' => 'Морковка',
]
];
$newArr = [];
$prevUri = "";
foreach ( $arr['Массив'] as $key => $name ) {
$uri = $prevUri ? "{$prevUri}/{$key}" : $key;
$newArr['Массив'][$key] = [
'name' => $name,
'uri' => $uri,
];
$prevUri = $uri;
}
print_r($newArr);
Array
(
[Массив] => Array
(
[purchases] => Array
(
[name] => Покупки
[uri] => purchases
)
[food] => Array
(
[name] => Еда
[uri] => purchases/food
)
[vegetables] => Array
(
[name] => Овощи
[uri] => purchases/food/vegetables
)
[carrot] => Array
(
[name] => Морковка
[uri] => purchases/food/vegetables/carrot
)
)
)