3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function isStringOrNumeric($in) { return basename($in); } function test($carry, $value) { $carry[] = basename($value); return $carry; } $a = array( 'index.php', '../../../index.php', 'valami.txt'); var_dump(array_reduce($a, 'test')); /*$b = array_filter($a, 'isStringOrNumeric'); var_dump($a); var_dump($b);*/ if($b === $a) echo('Success!'); else echo('Fail!');
based on L2h32
Output for 5.0.4 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> string(9) "index.php" [1]=> string(9) "index.php" [2]=> string(10) "valami.txt" } Notice: Undefined variable: b in /in/HLE71 on line 17 Fail!
Output for 4.3.3 - 5.0.3
array(3) { [0]=> string(9) "index.php" [1]=> string(9) "index.php" [2]=> string(10) "valami.txt" } Notice: Undefined variable: b in /in/HLE71 on line 17 Fail!
Output for 4.3.2
Fatal error: [] operator not supported for strings in /in/HLE71 on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: [] operator not supported for strings in /in/HLE71 on line 7