The abs()
function returns the absolute value of a number.
Figure 1 below shows the mathematical representation of the abs()
function.
number abs(num)
# num is the number whose absolute value is required
The abs()
function takes a number as a parameter.
The abs()
function returns the absolute value of a number passed as a parameter.
If a
string
is passed to this function, it returns0
.
<?php#Positive numberecho("abs(10): ");echo (abs(10));?><?php#Negative numberecho("abs(-10): ");echo (abs(-10));?><?php#zeroecho("abs(0): ");echo (abs(0));?><?php#stringecho("abs('hello): ");echo (abs('hello'));?>