3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['a' => 1, 'c' => 0]; function neverEmpty($firstChoice, $alternative) { return empty($firstChoice) ? $alternative : $firstChoice; } foreach (['a', 'b', 'c'] as $k) { var_export(neverEmpty($array[$k], 'nope')); echo "\n"; }
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
1 Warning: Undefined array key "b" in /in/sPgG7 on line 10 'nope' 'nope'

preferences:
70.39 ms | 1115 KiB | 4 Q