3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
57.56 ms | 402 KiB | 5 Q