PHP

1. PHP abs() Function:-
Definition and Usage
The abs() function returns the absolute value of a number.
Syntax
abs(x)
Parameter
Description
x
Required. A number. If the number is of type float, the return type is also float, otherwise it is integer
Example:-
<?php echo(abs(6.7) . "<br />"); echo(abs(-3) . "<br />"); echo(abs(3)); ?>
The output of the code above will be:
6.7 3 3
2. PHP base_convert() Function:-
Definition and Usage
The base_convert() function converts a number from one base to another.
Syntax
base_convert(number,frombase,tobase)
Parameter
Description
number
Required. Original value
frombase
Required. Original base of number. Frombase has to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35.
tobase
Required. The base to convert to. Tobase has to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35.
Example 1:-
Convert an octal number to a decimal number:
<?php $oct = "0031"; $dec = base_convert($oct,8,10); echo "$oct in octal is equal to $dec in decimal."; ?>
The output of the code above will be:
0031 in octal is equal to 25 in decimal.
Example 2:-
Convert an octal number to a hexadecimal number:
<?php $oct = "364"; $hex = base_convert($oct,8,16); echo "$oct in octal is equal to $hex in hexadecimal."; ?>
The output of the code above will be:
364 in octal is equal to f4 in hexadecimal.
3. PHP Ceil() Function:-
Definition and Usage
The ceil() function returns the value of a number rounded UPWARDS to the nearest integer.
Syntax
ceil(x)
Parameter
Description
x
Required. A number
Example:-
In the following example we will use the ceil() function on different numbers:
<?php echo(ceil(0.60) . "<br />"); echo(ceil(0.40) . "<br />"); echo(ceil(5) . "<br />"); echo(ceil(5.1) . "<br />"); echo(ceil(-5.1) . "<br />"); echo(ceil(-5.9)) ?>
The output of the code above will be:
1 1 5 6 -5 -5
4. PHP exp() Function:-
Definition and Usage
The exp() function returns the value of Ex, where E is Euler's constant (approximately 2.7183) and x is the number passed to it.
Syntax
exp(x)
Parameter
Description
x
Required. A number
Tips and Notes
Tip: E is the Euler's constant, which is the base of natural logarithms (approximately 2.7183).
Example
In the following example we will use the exp() function on different numbers:
<?php echo(exp(1) . "<br />"); echo(exp(-1) . "<br />"); echo(exp(5) . "<br />"); echo(exp(10)) ?>
The output of the code above will be:
2.718281828459045 0.36787944117144233 148.4131591025766 22026.465794806718
5. PHP floor() Function:-
Definition and Usage
The floor() function returns the value of a number rounded DOWNWARDS to the nearest integer.
Syntax
floor(x)
Parameter
Description
x
Required. A number
Example:-
In this example we will use the floor() function on different numbers:
<?php echo(floor(0.60) . "<br />");
echo(floor(0.40) . "<br />"); echo(floor(5) . "<br />"); echo(floor(5.1) . "<br />"); echo(floor(-5.1) . "<br />"); echo(floor(-5.9)) ?>
The output of the code above will be:
0 0 5 5 -6 -6
6. PHP fmod() Function:-
Definition and Usage
The fmod() function divides x by y and returns the remainder (modulo) of the division.
Syntax
fmod(x,y)
Parameter
Description
x
Required. A number
y
Required.
Example:-
In the following example we will use the fmod() function to return the remainder of 5/2:
<?php $r = fmod(5,2); echo $r ?>
The output of the code above will be:
1
7. PHP is_finite() Function:-
Definition and Usage
The is_finite() function returns true if the specified value is a finite number, otherwise it returns nothing.
The value is finite if it is within the allowed range for a PHP float on this platform.
Syntax
is_finite(x)
Parameter
Description
X
Required. The value to check
Example:-
<?php echo is_finite(2) . "<br />"; echo is_finite(log(0)) . "<br />"; echo is_finite(2000); ?>
The output of the code above will be:
1 1
8. PHP is_infinite() Function:-
Definition and Usage
The is_infinite() function returns true if the specified value is an infinite number, otherwise it returns nothing.
The value is infinite if it is too big to fit into a PHP float on this platform.
Syntax
is_infinite(x)
Parameter
Description
X
Required. The value to check
Example:-
<?php echo is_infinite(2) . "<br />"; echo is_infinite(log(0)) . "<br />"; echo is_infinite(2000); ?>
The output of the code above will be:
1
9. PHP lcg_value() Function:-
Definition and Usage
The lcg_value() function returns a pseudo random number in the range of 0 and 1.
Syntax
Lcg_value()
Example:-
<?php echo lcg_value(); ?>
The output of the code above could be:
0.408212029326
10. PHP log() Function:-
Definition and Usage
The log() function returns the natural logarithm (base E) of a number.
Syntax
Log(x,base)
Parameter
Description:-
X
Required. A number
base
Optional. If the base parameter is specified, log() returns logbase x. Note: The base parameter became available in PHP 4.
Tips and Notes
Note: If the parameter x is negative, -1.#IND is returned.
Example:-
In the following example we will use the log() function on different numbers:
<?php echo(log(2.7183) . "<br />"); echo(log(2) . "<br />"); echo(log(1) . "<br />"); echo(log(0) . "<br />"); echo(log(-1)) ?>
The output of the code above will be:
1.00000668491 0.69314718056 0 -1.#INF -1.#IND

No comments:

Post a Comment