3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $myArray = Array ( Array ( 'id' => 6, 'title' => 'zzz', 'parentID' => 0, 'parentName' =>'', 'section' => 'articles', 'sort' => 0, 'level' => 0 ), Array ( Array ( 'id' => 7, 'title' => 7, 'parentID' => 6, 'parentName' => '', 'section' => 'articles', 'sort' => 0, 'level' => 0 ), Array ( Array ( 'id' => 8, 'title' => 8, 'parentID' => 7, 'parentName' =>'' , 'section' => 'articles', 'sort' => 0, 'level' => 0 ) ) ), Array ( 'id' => 1, 'title' => '?a?3?a', 'parentID' => 0, 'parentName' => '', 'section' => 'articles', 'sort' => 0, 'level' => 0 ), Array ( Array ( 'id' => 4, 'title' => 4, 'parentID' => 1, 'parentName' => '', 'section' => 'articles', 'sort' => 0, 'level' => 0 ), Array ( 'id' => 5, 'title' => 5, 'parentID' => 1, 'parentName' => '', 'section' => 'articles', 'sort' => 0, 'level' => 0 ) ) ); function arrayStack( $array, $dash ){ foreach($array as $value){ if(isset($value['id'])){ echo str_repeat("-", $dash).$value['id'].'\n'; }else{ $dash++; arrayStack( $value, $dash ); $dash--; } } } arrayStack( $myArray, 0 );
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
6\n-7\n--8\n1\n-4\n-5\n