3v4l.org

run code in 300+ PHP versions simultaneously
<?php $raw = array( 'firstname' => 'Foo', 'lastname' => 'Bar', 'nickname' => '', 'birthdate' => [ 'day' => '', 'month' => '', 'year' => '', ], 'likes' => [ 'cars' => ['Subaru Impreza WRX STi', 'Mitsubishi Evo', 'Nissan GTR'], 'bikes' => [], ], 'zero' => 0, 'deeper' => [ 'zeroString' => '0', 'null' => null ], 'false' => false, ); function recursivelyRemoveEmpties(array $array): array { foreach ($array as $key => &$value) { if (is_array($value)) { $value = recursivelyRemoveEmpties($value); if (!$value) { unset($array[$key]); } continue; } if ($value === '') { unset($array[$key]); } } return $array; } var_export(recursivelyRemoveEmpties($raw));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'firstname' => 'Foo', 'lastname' => 'Bar', 'likes' => array ( 'cars' => array ( 0 => 'Subaru Impreza WRX STi', 1 => 'Mitsubishi Evo', 2 => 'Nissan GTR', ), ), 'zero' => 0, 'deeper' => array ( 'zeroString' => '0', 'null' => NULL, ), 'false' => false, )

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:
29.92 ms | 406 KiB | 5 Q