3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); $array = ['A', 'AA', 'AAA']; $arrayWithKeys = ['A' => 1, 'AA' => 2, 'AAA' => 3]; echo "array_find examples" . PHP_EOL; var_dump(array_find($array, static fn(string $value): bool => strlen($value) > 2)); // returns AAA var_dump(array_find($array, static fn(string $value): bool => strlen($value) > 3)); // returns null var_dump(array_find($arrayWithKeys, static fn(int $value, string $key): bool => $value === strlen($key))); // returns 1 echo PHP_EOL . "array_find_key examples" . PHP_EOL; var_dump(array_find_key($array, static fn(string $value): bool => strlen($value) > 2)); // returns 2 var_dump(array_find_key($array, static fn(string $value): bool => strlen($value) > 3)); // returns null var_dump(array_find_key($arrayWithKeys, static fn(int $value, string $key): bool => $value === strlen($key))); // returns A echo PHP_EOL . "array_any examples" . PHP_EOL; var_dump(array_any($array, static fn(string $value): bool => strlen($value) > 2)); // returns true var_dump(array_any($arrayWithKeys, static fn(int $value, string $key): bool => $value === strlen($key))); // returns true echo PHP_EOL . "array_all examples" . PHP_EOL; var_dump(array_all($array, static fn(string $value): bool => strlen($value) < 4)); // returns true var_dump(array_all($arrayWithKeys, static fn(int $value, string $key): bool => $value === strlen($key))); // returns true
Output for 8.4.1 - 8.4.14, 8.5.0
array_find examples string(3) "AAA" NULL int(1) array_find_key examples int(2) NULL string(1) "A" array_any examples bool(true) bool(true) array_all examples bool(true) bool(true)
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.1.30 - 8.1.33, 8.2.24 - 8.2.29, 8.3.5 - 8.3.28
array_find examples Fatal error: Uncaught Error: Call to undefined function array_find() in /in/8MNU0:9 Stack trace: #0 {main} thrown in /in/8MNU0 on line 9
Process exited with code 255.

preferences:
44.31 ms | 409 KiB | 5 Q