3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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'; }));
based on aYeLK
Output for 7.1.0 - 7.2.0
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.4.9 - 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) { }
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/oPX72 on line 3
Process exited with code 255.