3v4l.org

run code in 500+ PHP versions simultaneously
<?php $tests = [ [], // expect null [true, true], // expect true [false, false], // expect false [true, false, true], // expect null [false, true, false], // expect null ]; foreach ($tests as $bools) { echo "\n"; var_export( !$bools || ( ($hasTrues = array_any($bools, fn($b) => $b === true)) && array_any($bools, fn($b) => $b === false) ) ? null : $hasTrues ); }
Output for 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
NULL true false NULL NULL
Output for 8.1.30 - 8.1.34, 8.2.23 - 8.2.30, 8.3.5 - 8.3.30
NULL Fatal error: Uncaught Error: Call to undefined function array_any() in /in/uNdNI:16 Stack trace: #0 {main} thrown in /in/uNdNI on line 16
Process exited with code 255.

preferences:
50.4 ms | 718 KiB | 4 Q