Integer Experiments

Back to
Back to Library
Back to PHP Experiment

Integers store numerical data.

PHP_INT_MAX: 9223372036854775807
To test if an variable is an integer use is_int or is_integer, is_long.
To see if a variable is an integer value use is_numeric
To convert a value to integer use intval(number,base)There are 4 types of integers, decimal, Hexadecimal, octal and binary
Decimal [1-9][0-9]*| 0
Octal: 0[0-7]+
Binary: 0b[01]+
Basically the rules as follows, if it does not start with a 0 or is equal to 0 than it is decimal. If it starts with a 0 and then numbers follow it is octal. If the number starts with 0x or 0X than it is hexadecimal. If the number starts with 0b then it is binary data.
You can cast to integer with (int) or (integer)
Integers can start with either + or - as well as neither + or -. PHP integers cannot be unsigned
When a boolean is converted to an intger, it will make 1 for true and 0 for false
PHP Integer type