3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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'); var_dump($arr); } } A::run();
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0
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]=> string(3) "078" [9]=> string(4) "0.78" [10]=> float(0.78) [11]=> float(0.78) }
Output for 5.1.0 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/su6Um on line 14
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/su6Um 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/su6Um on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/su6Um 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/su6Um on line 3
Process exited with code 255.