3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 'one' => '...', 'two' => [ 'three' => '...', 'four' => '...', 'five' => [ 'six' => '...', 'seven' => '...', ], ], ]; $fields = [ 'one', 'two' => [ 'four', 'five' => [ 'seven', ], ], ]; var_dump(filterRecursive($data, $fields)); function filterRecursive(array $data, array $fields) { foreach ( $data as $key => &$value ) { if ( is_array($fields[$key]) ) { $value = filterRecursive($value, $fields[$key]); } elseif ( !in_array($key, $fields) ) { unset($value); } } return $data; }
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined array key "one" in /in/Cust8 on line 30 Warning: Undefined array key "three" in /in/Cust8 on line 30 Warning: Undefined array key "four" in /in/Cust8 on line 30 Warning: Undefined array key "six" in /in/Cust8 on line 30 Warning: Undefined array key "seven" in /in/Cust8 on line 30 array(2) { ["one"]=> string(3) "..." ["two"]=> array(3) { ["three"]=> string(3) "..." ["four"]=> string(3) "..." ["five"]=> array(2) { ["six"]=> string(3) "..." ["seven"]=> string(3) "..." } } }

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:
43.58 ms | 402 KiB | 8 Q