PHP Basic Tutorial
MySQL Connection
Numbers are a data type used for mathematical calculations and numerical data processing. PHP supports different types of numbers, such as integers, floating-point numbers (floats), and provides a wide range of functions to perform mathematical operations.
PHP has two more data types
Range of an Integer:
On a 32-bit system, integers typically range from -2,147,483,648 to 2,147,483,647.
On a 64-bit system, the range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Decimal (Base 10): 123
Hexadecimal (Base 16): Prefixed with 0x
(e.g., 0x1A
)
Octal (Base 8): Prefixed with 0
(e.g., 0123
)
Binary (Base 2): Prefixed with 0b
(e.g., 0b1010
)
PHP_INT_MAX
- The largest integer supportedPHP_INT_MIN
- The smallest integer supportedPHP_INT_SIZE
- The size of an integer in bytesis_int()
, is_integer()
, is_long()
functions to check if the type of a variable is integer.
Try it yourself
1.5e3
).PHP_FLOAT_MAX
- The largest representable floating point numberPHP_FLOAT_MIN
- The smallest representable positive floating point numberPHP_FLOAT_DIG
- The number of decimal digits that can be rounded into a float and back without precision lossPHP_FLOAT_EPSILON
- The smallest representable positive number x, so that x + 1.0 != 1.0is_float()
, is_double()
functions to check if the type of a variable is float.
Try it yourself
Numerical strings are strings that contain numbers and can be treated as numbers in certain situations. When a string contains a numeric value (either integer or floating-point), PHP can automatically treat it as a number when used in arithmetic operations or comparisons.
Try it yourself
Infinity is a special value that represents a number beyond the range that can be represented by a float. It is denoted by the constant INF
for positive infinity and -INF
for negative infinity.
PHP_FLOAT_MAX
.-PHP_FLOAT_MAX
.is_finite()
, is_infinite()
functions to check if a numeric value is finite or infinite.
Try it yourself
NAN (Not A Number) is a special floating-point value that represents the result of an undefined or unrepresentable mathematical operation.
For example, operations like taking the square root of a negative number or dividing zero by zero can produce a NaN result.
To check if a value is NaN, you can use the is_nan()
function. This function returns true
if the value is NAN, otherwise false
.
PHP offers various ways to cast a numerical value into another data type.
The (int)
, (integer)
, and intval()
functions are often used to convert a value to an integer.
Try it yourself