@ 2018-10-31T15:13:23Z <?php
$arr = array(
0 => array(
"text" => "eventyrer",
"children"=> array(
4 => array(
"text" => "news",
"children"=> array(
1=> array("text"=>"a")
)
),
5 => array(
"text" => "nyheter",
"children"=> array(
1=> array("text"=>"b")
)
)
)
),
1 => array(
"text" => "eventyrer2017",
"children"=> array(
6 => array(
"text" => "news",
"children"=> array(
1=> array("text"=>"c")
)
),
8 => array(
"text" => "nyheter",
"children"=> array(
1=> array(
"text"=>"d",
"children"=> array(
1=> array("text"=>"e")
)
)
)
)
)
)
);
$new_array = [];
foreach($arr as &$value) {
//loop through first set
foreach($value['children'] as $child) {
//loop through children, create a string that contains the first set of values "text", and the childrens "text"
$string = "{$value['text']}/{$child['text']}";
foreach($child['children'] as $child2) {
//loop through each child of child1 and add a new string to the new_array containing `$string` + the child2.
$new_array[] = $string .= "/{$child2['text']}";
}
}
}
var_export($new_array);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.6.38 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 array (
0 => 'eventyrer/news/a',
1 => 'eventyrer/nyheter/b',
2 => 'eventyrer2017/news/c',
3 => 'eventyrer2017/nyheter/d',
) Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
0 => 'eventyrer/news/a',
1 => 'eventyrer/nyheter/b',
2 => 'eventyrer2017/news/c',
3 => 'eventyrer2017/nyheter/d',
) preferences:dark mode live preview
168.35 ms | 402 KiB | 203 Q