3v4l.org

run code in 300+ PHP versions simultaneously
<?php $groupList = [ [ 'id' => 1, 'parent_id' => null, 'category' => null, 'children_list' => [ [ 'id' => 3, 'parent_id' => 1, 'category' => null, ], [ 'id' => 4, 'parent_id' => 1, 'category' => 'Category number 20', 'children_list' => [ [ 'id' => 7, 'parent_id' => 4, 'category' => null, ], [ 'id' => 8, 'parent_id' => 4, 'category' => 'Category number 30', ], ], ], ], ], 'id' => 2, 'parent_id' => null, 'category' => null, 'children_list' => [ [ 'id' => 5, 'parent_id' => 2, 'category' => null, 'children_list' => [ [ 'id' => 6, 'parent_id' => 5, 'category' => null, ], ], ], ], ]; $filter = array_map(function ($n){return f($n);}, $groupList[0]); echo '<pre>'; print_r($filter); function f(&$a){ foreach($a as $k=>&$r){ if(!$r['category']) unset($a[$k]); if($r['children_list']) $r['children_list']=f($r['children_list']); } return $a; }
Output for git.master, git.master_jit, rfc.property-hooks
Warning: foreach() argument must be of type array|object, int given in /in/T2Rba on line 59 Warning: foreach() argument must be of type array|object, null given in /in/T2Rba on line 59 Warning: foreach() argument must be of type array|object, null given in /in/T2Rba on line 59 Warning: Undefined array key "children_list" in /in/T2Rba on line 61 Warning: Undefined array key "children_list" in /in/T2Rba on line 61 Warning: Undefined array key "children_list" in /in/T2Rba on line 61 <pre>Array ( [id] => 1 [parent_id] => [category] => [children_list] => Array ( [1] => Array ( [id] => 4 [parent_id] => 1 [category] => Category number 20 [children_list] => Array ( [1] => Array ( [id] => 8 [parent_id] => 4 [category] => Category number 30 ) ) ) ) )

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:
41.09 ms | 408 KiB | 5 Q