3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<? $values = array( '-0', -0, 0, 123, -123, '123', '-123', '0123', '123 ', '0', '000', '+123', '1.23', 1.23, '123e4', '0x123', 'potato', 'EEBD', false, null, ); foreach($values as $value){ echo("TRYING WITH "); var_dump($value); echo("is_int: "); var_dump(is_int($value)); echo("is_numeric: "); var_dump(is_numeric($value)); echo("regex: "); var_dump(preg_match('/^\-?[0-9]+$/',$value)); echo("ctype_digit: "); var_dump(ctype_digit(ltrim((string)$value, '-'))); echo("filter_var: "); var_dump(filter_var($value, FILTER_VALIDATE_INT)); echo("\n"); echo("\n"); } ?>
based on QlBFS
Output for 7.0.0 - 7.2.0
TRYING WITH string(2) "-0" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH int(0) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH int(0) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH int(123) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(123) TRYING WITH int(-123) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(-123) TRYING WITH string(3) "123" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(123) TRYING WITH string(4) "-123" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(-123) TRYING WITH string(4) "0123" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: bool(false) TRYING WITH string(4) "123 " is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: int(123) TRYING WITH string(1) "0" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH string(3) "000" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: bool(false) TRYING WITH string(4) "+123" is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: int(123) TRYING WITH string(4) "1.23" is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH float(1.23) is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(5) "123e4" is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(5) "0x123" is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(6) "potato" is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(4) "EEBD" is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH bool(false) is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH NULL is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false)
Output for 5.4.11 - 5.6.28
TRYING WITH string(2) "-0" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH int(0) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH int(0) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH int(123) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(123) TRYING WITH int(-123) is_int: bool(true) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(-123) TRYING WITH string(3) "123" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(123) TRYING WITH string(4) "-123" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(-123) TRYING WITH string(4) "0123" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: bool(false) TRYING WITH string(4) "123 " is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: int(123) TRYING WITH string(1) "0" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: int(0) TRYING WITH string(3) "000" is_int: bool(false) is_numeric: bool(true) regex: int(1) ctype_digit: bool(true) filter_var: bool(false) TRYING WITH string(4) "+123" is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: int(123) TRYING WITH string(4) "1.23" is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH float(1.23) is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(5) "123e4" is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(5) "0x123" is_int: bool(false) is_numeric: bool(true) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(6) "potato" is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH string(4) "EEBD" is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH bool(false) is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false) TRYING WITH NULL is_int: bool(false) is_numeric: bool(false) regex: int(0) ctype_digit: bool(false) filter_var: bool(false)
Output for 5.3.21 - 5.3.29
<? $values = array( '-0', -0, 0, 123, -123, '123', '-123', '0123', '123 ', '0', '000', '+123', '1.23', 1.23, '123e4', '0x123', 'potato', 'EEBD', false, null, ); foreach($values as $value){ echo("TRYING WITH "); var_dump($value); echo("is_int: "); var_dump(is_int($value)); echo("is_numeric: "); var_dump(is_numeric($value)); echo("regex: "); var_dump(preg_match('/^\-?[0-9]+$/',$value)); echo("ctype_digit: "); var_dump(ctype_digit(ltrim((string)$value, '-'))); echo("filter_var: "); var_dump(filter_var($value, FILTER_VALIDATE_INT)); echo("\n"); echo("\n"); } ?>