3v4l.org

run code in 500+ PHP versions simultaneously
<?php function test($var, array $G, array $P) { if (empty($var)) { return; } if (isset($P[$var])) { $value = $P[$var]; } elseif (isset($G[$var])) { $value = $G[$var]; } else { $value = null; } return $value; } function test2($var, array $G, array $P) { return $P[$var] ?? $G[$var] ?? null; } $G = ['a' => 'A', 'b' => '', 'c' => 'C']; $P = ['b' => 'B', 'c' => '']; var_dump(test('a', $G, $P)) . PHP_EOL; var_dump(test('b', $G, $P)) . PHP_EOL; var_dump(test('c', $G, $P)) . PHP_EOL; var_dump(test('', $G, $P)) . PHP_EOL; print '-----' . PHP_EOL; var_dump(test2('a', $G, $P)) . PHP_EOL; var_dump(test2('b', $G, $P)) . PHP_EOL; var_dump(test2('c', $G, $P)) . PHP_EOL; var_dump(test2('', $G, $P)) . PHP_EOL;
Output for 8.3.6 - 8.3.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.12, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.36, 8.3.0 - 8.3.4
string(1) "A" string(1) "B" string(0) "" NULL ----- string(1) "A" string(1) "B" string(0) "" NULL
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 string(1) "A" string(1) "B" string(0) "" NULL ----- string(1) "A" string(1) "B" string(0) "" NULL

preferences:
20.36 ms | 1171 KiB | 6 Q