Array
(
[1] => stdClass Object
(
[id] => 1
[parent_id] => 0
[name] => Первый
[url] => perviy
[level] => 1
[subcategories] => Array
(
[0] => stdClass Object
(
[id] => 2
[parent_id] => 1
[name] => Второй
[url] => vtoroy
[level] => 2
[subcategories] => Array
(
[0] => stdClass Object
(
[id] => 3
[parent_id] => 2
[name] => Третий
[url] => tretiy
[level] => 3
)
)
)
)
),
[2] => stdClass Object
(
[id] => 4
[parent_id] => 0
[name] => Четвертый
[url] => chetvertiy
[level] => 1
[subcategories] => Array
(
)
)
)
perviy
perviy/vtoroy
perviy/vtoroy/tretiy
chetvertiy
function getUrls($tree, $url = '') {
$urls = [];
foreach ($tree as $n) {
$newUrl = ($url ? $url.'/' : '').$n->url;
array_push($urls, $newUrl, ...getUrls($n->subcategories ?? [], $newUrl));
}
return $urls;
}