3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'abc' => 0, 'foo-bcd' => 1, 'foo-def' => 1, 'foo-xyz' => 0, ]; $prefix = 'foo'; var_export( array_filter( $array, fn($key) => str_starts_with($key, $prefix), ARRAY_FILTER_USE_KEY ) );
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 'foo-bcd' => 1, 'foo-def' => 1, 'foo-xyz' => 0, )
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Call to undefined function str_starts_with() in /in/Nog5U:15 Stack trace: #0 [internal function]: {closure}('abc') #1 /in/Nog5U(16): array_filter(Array, Object(Closure), 2) #2 {main} thrown in /in/Nog5U on line 15
Process exited with code 255.
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/Nog5U on line 15
Process exited with code 255.
Output for 7.2.0 - 7.2.34
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')' in /in/Nog5U on line 15
Process exited with code 255.

preferences:
152.41 ms | 410 KiB | 5 Q