3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( array ( 'category_id' => 20, 'category_name' => 'Category 1', 'main_category' => 0, 'sub_categories' => array( array ( 'category_id' => 25, 'category_name' => 'Category 1.3', 'main_category' => 20, 'sub_categories' => [], ), array ( 'category_id' => 26, 'category_name' => 'Category 1.4', 'main_category' => 20, 'sub_categories' => array ( array ( 'category_id' => 30, 'category_name' => 'Category 1.4.1', 'main_category' => 26, 'sub_categories' => [] ), array ( 'category_id' => 31, 'category_name' => 'Category 1.4.2', 'main_category' => 26, 'sub_categories' => [] ) ) ), ) ), array ( 'category_id' => 19, 'category_name' => 'Category 2', 'main_category' => 0, 'sub_categories' => [] ) ); function getChildren($data,$parents,&$result){ foreach($data as $current_category){ $temp = []; $temp['category_id'] = $current_category['category_id']; $new_cat_sequence = array_merge($parents,[$current_category['category_name']]); $temp['category_name'] = implode(" -> ",$new_cat_sequence); $result[] = $temp; getChildren($current_category['sub_categories'],$new_cat_sequence,$result); } } $result = []; getChildren($data,[],$result); print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [category_id] => 20 [category_name] => Category 1 ) [1] => Array ( [category_id] => 25 [category_name] => Category 1 -> Category 1.3 ) [2] => Array ( [category_id] => 26 [category_name] => Category 1 -> Category 1.4 ) [3] => Array ( [category_id] => 30 [category_name] => Category 1 -> Category 1.4 -> Category 1.4.1 ) [4] => Array ( [category_id] => 31 [category_name] => Category 1 -> Category 1.4 -> Category 1.4.2 ) [5] => Array ( [category_id] => 19 [category_name] => Category 2 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.73 ms | 407 KiB | 5 Q