3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'a' => 'a', 'b' => '', 'c' => null, 'd' => 122, 'e' => 0, 'f' => [ 'g' => 'g', 'h' => 0, 'i' => null, 'j' => '' ] ]; $result = array_filter($array, function ($arr) { if (!is_array($arr)) { return strlen($arr) ; } return array_filter($arr) ; } ) ; var_dump($result);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/XivSI on line 19 array(4) { ["a"]=> string(1) "a" ["d"]=> int(122) ["e"]=> int(0) ["f"]=> array(4) { ["g"]=> string(1) "g" ["h"]=> int(0) ["i"]=> NULL ["j"]=> string(0) "" } }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/XivSI on line 19 array(4) { ["a"]=> string(1) "a" ["d"]=> int(122) ["e"]=> int(0) ["f"]=> array(4) { ["g"]=> string(1) "g" ["h"]=> int(0) ["i"]=> NULL ["j"]=> string(0) "" } }
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
array(4) { ["a"]=> string(1) "a" ["d"]=> int(122) ["e"]=> int(0) ["f"]=> array(4) { ["g"]=> string(1) "g" ["h"]=> int(0) ["i"]=> NULL ["j"]=> string(0) "" } }

preferences:
175.29 ms | 402 KiB | 172 Q