3v4l.org

run code in 300+ PHP versions simultaneously
<?php $list = [ 'foo' => 'bar', 'foobar' => 'bar', 'bar' => 'foo', ]; var_dump(array_filter($list, function ($value) { return $value === 'bar'; })); var_dump(array_filter($list, function ($key, $value) { return $value === 'bar'; }));
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(2) { ["foo"]=> string(3) "bar" ["foobar"]=> string(3) "bar" } Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed and exactly 2 expected in /in/oPX72:13 Stack trace: #0 [internal function]: {closure}('bar') #1 /in/oPX72(13): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/oPX72 on line 13
Process exited with code 255.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27
array(2) { ["foo"]=> string(3) "bar" ["foobar"]=> string(3) "bar" } Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed and exactly 2 expected in /in/oPX72:13 Stack trace: #0 [internal function]: {closure}('bar') #1 /in/oPX72(15): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/oPX72 on line 13
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20
array(2) { ["foo"]=> string(3) "bar" ["foobar"]=> string(3) "bar" } Warning: Missing argument 2 for {closure}() in /in/oPX72 on line 13 Notice: Undefined variable: value in /in/oPX72 on line 14 Warning: Missing argument 2 for {closure}() in /in/oPX72 on line 13 Notice: Undefined variable: value in /in/oPX72 on line 14 Warning: Missing argument 2 for {closure}() in /in/oPX72 on line 13 Notice: Undefined variable: value in /in/oPX72 on line 14 array(0) { }

preferences:
185.49 ms | 402 KiB | 194 Q