3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function is_natural($val) { $val = (string)$val; return (bool)ctype_digit($val) && $val === (string)(int)$val && $val > 0; } var_dump(is_natural(15)); // true var_dump(is_natural(0)); // false var_dump(is_natural(-1)); // false var_dump(is_natural('5')); // true var_dump(is_natural('01')); // false var_dump(is_natural('1.5')); // false var_dump(is_natural('0x18')); // false
Output for 4.3.0 - 5.0.5, 5.1.1 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
bool(true) bool(false) bool(false) bool(true) bool(false) bool(false) bool(false)
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/DHWR9 on line 12
Process exited with code 255.