3v4l.org

run code in 300+ PHP versions simultaneously
<?php function filter($array, callable $c) { $result = []; foreach ($array as $key => $value) { if ($c($value, $key)) { $result[$key] = $value; } } return $result; } var_dump(filter(['foo', '', 'bar'], function ($value) { return strlen($value); })); // Internal functions already throw on superfluous args var_dump(filter(['foo', '', 'bar'], 'strlen'));
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(2) { [0]=> string(3) "foo" [2]=> string(3) "bar" } Fatal error: Uncaught ArgumentCountError: strlen() expects exactly 1 argument, 2 given in /in/0QdoS:6 Stack trace: #0 /in/0QdoS(6): strlen('foo', 0) #1 /in/0QdoS(18): filter(Array, 'strlen') #2 {main} thrown in /in/0QdoS on line 6
Process exited with code 255.

preferences:
83.1 ms | 402 KiB | 62 Q