3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $values = [ '0', '-0', '1', '-1', '0.0', '1.1', '-1.1', '0x111', '0111', '0b111', '-0x111', '-0111', '-0b111', '0.1e2', '-0.1e2', '0.1e-2', '-0.1e-2', ]; printf(' string | float | int' . PHP_EOL); foreach ($values as $value) { $float = filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_SCALAR); $int = filter_var($value, FILTER_VALIDATE_INT, FILTER_REQUIRE_SCALAR); printf('%7s | %6s | %2s%s', $value, $float, $int, PHP_EOL); }
based on 2MGsG
Output for 5.6.0 - 7.3.0rc4
string | float | int 0 | 0 | 0 -0 | 0 | 0 1 | 1 | 1 -1 | -1 | -1 0.0 | 0 | 1.1 | 1.1 | -1.1 | -1.1 | 0x111 | | 0111 | 111 | 0b111 | | -0x111 | | -0111 | -111 | -0b111 | | 0.1e2 | 10 | -0.1e2 | -10 | 0.1e-2 | 0.001 | -0.1e-2 | -0.001 |