PHP Tutorial
PHP Numbers
PHP Integer
An Integer is a non-decimal number.
An Integer can either be positive or negative.
In PHP, an Integer will be stored as a float if its value exceeds the maximum size of an Integer.
<?php
$var = 15;
var_dump($var); //outputs: int(15)
?>
PHP has built-in constants for like PHP_INT_MAX
for the maximum integer supported by PHP, PHP_INT_MIN
for the minimum integer supported by PHP and PHP_INT_SIZE
for PHP integer size in bytes.
PHP has built-in functions like is_int()
, is_integer()
, is_long()
can be used to check if a type of a value is an integer.
<?php
$integer_var = 20;
$float_var = 2.0;
var_dump(is_int($integer_var)); //outputs: bool(true)
var_dump(is_integer($integer_var)); //outputs: bool(true)
var_dump(is_long($integer_var)); //outputs: bool(true)
var_dump(is_int($float_var)); //outputs: bool(false)
var_dump(is_integer($float_var)); //outputs: bool(false)
var_dump(is_long($float_var)); //outputs: bool(false)
?>
PHP Float
A Float or Double is a decimal number.
A Float can be in an Exponential form.
None
PHP has built-in constants for like PHP_FLOAT_MAX
for the maximum float number supported by PHP, PHP_FLOAT_MIN
for the minimum float number supported by PHP, PHP_FLOAT_DIG
for PHP float number of decimal digits that can be rounded without precision loss.
In PHP, if a number is greater than the PHP_FLOAT_MAX that number is infinite.
PHP has built-in functions like is_float()
, is_double()
can be used to check if the type of a value is a float.
What You Should Know at the End of This Lesson
- You should know about PHP Integers.
- You should know about PHP Floating-Point Numbers.
- You should know about PHP built-in functions.