3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { static function cast(&$val, $key, $allow_zero_first_character = false) { if (is_numeric($val)) { if($allow_zero_first_character || (!$allow_zero_first_character && $val[0] != '0')) { $val += 0; } } } static function run() { $arr = ['stri33ng123', 84, 76.7, '45.6', '67.5e45', '56,9', 078, 0.78, '078', '0.78', .78, '.78']; var_dump($arr); //array_walk($arr , ['self', 'cast']); array_walk($arr , 'self::cast', true); var_dump($arr); } } A::run();
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
array(12) { [0]=> string(11) "stri33ng123" [1]=> int(84) [2]=> float(76.7) [3]=> string(4) "45.6" [4]=> string(7) "67.5e45" [5]=> string(4) "56,9" [6]=> int(7) [7]=> float(0.78) [8]=> string(3) "078" [9]=> string(4) "0.78" [10]=> float(0.78) [11]=> string(3) ".78" } array(12) { [0]=> string(11) "stri33ng123" [1]=> int(84) [2]=> float(76.7) [3]=> float(45.6) [4]=> float(6.75E+46) [5]=> string(4) "56,9" [6]=> int(7) [7]=> float(0.78) [8]=> int(78) [9]=> float(0.78) [10]=> float(0.78) [11]=> float(0.78) }
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/8E0YD on line 14
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/8E0YD on line 14
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8E0YD on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8E0YD on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/8E0YD on line 3
Process exited with code 255.

preferences:
251.31 ms | 1395 KiB | 161 Q