PHP Math Functions | gmp_sign() | abs()


PHP Mathematical Constants & Functions:
- To perform mathematical calculations easily PHP provides various mathematical functions and constants.

gmp_sign(value: int /string):int
- is used to test whether the given value is a +ve integer or a –ve integer or zero
- Returns 1 if given value is positive integer,
- Return -1 if given value is negative integer,
- Returns 0 if given value is 0
echo gmp_sign(22); // 1
echo gmp_sign(-22); // -1
echo gmp_sign(0); // 0

echo gmp_sign("22"); // 1
echo gmp_sign("-22"); // -1
echo gmp_sign("0"); //0

abs(value: number):number
- Returns the absolute value (+ve) of the given number.
echo abs(-29); //29
echo abs(-29.5); //29.5

Interview Questions:

1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a