$urlFragments = [
'pozdravlenya',
'na-angliyskom',
[ 'lubimoy', 'lubimomu' ],
'v-proze',
[ 'korotkie', 'nekorotkie' ]
];
Array
(
[0] => pozdravlenya/na-angliyskom/lubimoy/v-proze/korotkie
[1] => pozdravlenya/na-angliyskom/lubimoy/v-proze/nekorotkie
[2] => pozdravlenya/na-angliyskom/lubimomu/v-proze/korotkie
[3] => pozdravlenya/na-angliyskom/lubimomu/v-proze/nekorotkie
)
function getUrls($parts, $acc = '') {
$urls = [];
if (count($parts)) {
$part = array_shift($parts);
if (!is_array($part)) {
$part = [ $part ];
}
foreach ($part as $p) {
array_push($urls, ...getUrls($parts, ($acc ? $acc.'/' : '').$p));
}
} else {
$urls[] = $acc;
}
return $urls;
}
$urls = getUrls($urlFragments);