3v4l.org

run code in 500+ PHP versions simultaneously
<?php $objects = [ (object)['cats' => 2], (object)['dogs' => 2], (object)['fish' => 10], (object)['birds' => 1], ]; $needleField = 'cats'; $needleValue = 2; var_export( array_any( $objects, fn($obj) => property_exists($obj, $needleField) && $obj->$needleField === $needleValue ) );
Output for 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
true
Output for 8.1.30 - 8.1.34, 8.2.10 - 8.2.30, 8.3.5 - 8.3.30
Fatal error: Uncaught Error: Call to undefined function array_any() in /in/eYOuI:14 Stack trace: #0 {main} thrown in /in/eYOuI on line 14
Process exited with code 255.

preferences:
61.3 ms | 732 KiB | 4 Q