Thursday, 18 June 2020

php math

math
abs gives absolut, if it is a postitve or negative, it will positive only
1. <?php  
2. echo (abs(-7)."<br/>"); // 7 (integer)   7
3. echo (abs(7)."<br/>"); //7 (integer)   7
4. echo (abs(-7.2)."<br/>"); //7.2 (float/double)   7.2
5. ?>  
ceil
1. <?php  
2. echo (ceil(3.3)."<br/>");// 4   4
3. echo (ceil(7.333)."<br/>");// 8   8
4. echo (ceil(-4.8)."<br/>");// -4   -4
5. ?>  
floor
1. <?php  
2. echo (floor(3.3)."<br/>");// 3   3
3. echo (floor(7.333)."<br/>");// 7   7
4. echo (floor(-4.8)."<br/>");// -5   -5
5. ?> 
sqrt
1. <?php  
2. echo (sqrt(16)."<br/>");// 4  
3. echo (sqrt(25)."<br/>");// 5  
4. echo (sqrt(7)."<br/>");// 2.6457513110646  
5. ?>  
decbin
1. <?php  
2. echo (decbin(2)."<br/>");// 10  
3. echo (decbin(10)."<br/>");// 1010  
4. echo (decbin(22)."<br/>");// 10110  
5. ?>  
dechex
1. <?php  
2. echo (dechex(2)."<br/>");// 2  
3. echo (dechex(10)."<br/>");// a  
4. echo (dechex(22)."<br/>");// 16  
5. ?>  
decoct
1. <?php  
2. echo (decoct(2)."<br/>");// 2  
3. echo (decoct(10)."<br/>");// 12  
4. echo (decoct(22)."<br/>");// 26  
5. ?>  
base
1. <?php  
2. $n1=10;  
3. echo (base_convert($n1,10,2)."<br/>");// 1010  
4. ?>   1010
string base_convert ( string $number , int $frombase , int $tobase )  
bindec
1. <?php   2
2. echo (bindec(10)."<br/>");// 2   10
3. echo (bindec(1010)."<br/>");// 10   11
4. echo (bindec(1011)."<br/>");// 11  
5. ?>  
sin()
sinh() used to return the hyperbolic sine of a number
asin() used to find the arc sine of anumber
asinh() used to find the inverse hyperbolic sine of a number
cos() used to find the cosine of a numbr
acosh() return the inverse hyperbolic cosine of a number.
tanh() hyperbolic tangent of a number
atan() arc tangent of a number in radians
atan2() used to return the arc tangent of a number in radians
atanh() used to return the inverse hyperbolic tangent of a number
pi() return the apporximation value of pi
deg2rad()
rad2deg()
exp() caliculate the exponent of e
expm1()) used to return exp(x)-1
floor() round a number down to the nearest integer
getrandmax() largest possible value returned by rand().
mt_getrandmax() used to find the largest possible random value
1. <?php  
2. echo "By using 'mt_getrandmax()' function your value is:".(mt_getrandmax());    By using 'mt_getrandmax()' function your value is:2147483647
3. ?>  
1. <?php  
2. function randomFloat($min = 0, $max = 1) {  
3.     return $min + mt_rand() / mt_getrandmax() * ($max - $min);   float(0.34399861858413) float(13.130184705895)
4. }  
5. var_dump(randomFloat());  
6. var_dump(randomFloat(2, 20));  
7. ?>  
hexadec()
octdec()
is_finite To check whether a value is finite or not.
log(0) bool(false)
45 bool(true)
is_infinite It is used to check whether a value is infinite or not.
acos(2) bool(false)
2
2000
log(0) 1
: It will returns true value when infinite number, otherwise it returns false /nothing.
1. <?php   
2. $infinite = log(0);   bool(false)
3. var_dump(is_finite($infinite));  
4. ?>  
is_nan It returns true if the value is not a number. Otherwise it returns false/nothing.
1. <?php   
2. $nos =200;  
3. echo "Your value is :".$nos;  
4. echo "<br>"."By using 'is_nan()' Function your value is:".is_nan($nos);   writes nothing
5. ?>  
acos(1.01) 1
40 bool(false)
log(0) bool(false)
acos(2) bool(true)
lcg_value
1. <?php   
2. echo "Note: Refresh page to get New Value";   Note: Refresh page to get New Value
3. echo lcg_value();   By using 'lcg_value()' Function your value is: 0.60141092827647
4. ?>
log() natural logarithm of a number
log10() return the base10 logarithm of a number
log1p() used to return log(1+number)
max() highest value in an array
min() lowest value in an array
mt_rand() generates integer using mersenne twister alogrithm
mt_srand() seeds the mersenne twister random number generatore
pow()
1. <?php  
2. $num=pow(3, 2);  
3. echo "Your number is = pow (3, 2)".'<br>';  
4. echo "By using sqrt function Your number is : ".$num;   3 square is 9
5. ?>  
intdiv
1. <?php  
2.  echo "Your Number is : (3,2)"."<br>";   Your Number is : (3,2)
3.  echo var_dump(intdiv(3, 2))." : is Output value";   int(1) : is Output value
4. ?>  
rand() used to generate a random numbe



round()
float round($number, $precision, $mode);  
number Specify the value to round Required
Precision Specify the number of decimal digits to round to. Optional
Mode Specify the mode in which rounding occurs. Optional
PHP_ROUND_HALF_UP
PHP_ROUND_HALF_DOWN
PHP_ROUND_HALF_EVEN
PHP_ROUND_HALF_ODD



1. <?php  
2. echo "Befor using round() function : 3.96754,2";  
Befor using round() function : 3.96754,2
3. echo "<br>"."After using round() function : ".(round(3.96754,2));  
After using round() function : 3.97
4. ?>  
1. <?php  
2. echo "Befor using round() function : 7.045,2";  
Befor using round() function : 7.045,2
3. echo "<br>"."After using round() function : ".(round(7.045,2));  
After using round() function : 7.05
4. ?>  
1. <?php  
2. echo(round(1.6,0,PHP_ROUND_HALF_UP) . "<br>");  
2
3. echo(round(-1.6,0,PHP_ROUND_HALF_UP) . "<br>");  
-2
4.   
1
5. echo(round(1.6,0,PHP_ROUND_HALF_DOWN) . "<br>");  
-1
6. echo(round(-1.6,0,PHP_ROUND_HALF_DOWN) . "<br>");  
2
7.   
-2
8. echo(round(1.6,0,PHP_ROUND_HALF_EVEN) . "<br>");  
1
9. echo(round(-1.6,0,PHP_ROUND_HALF_EVEN) . "<br>");  
-1
10.   
11. echo(round(1.6,0,PHP_ROUND_HALF_ODD) . "<br>");  
12. echo(round(-1.6,0,PHP_ROUND_HALF_ODD));  
13. ?>  
fmod
float fmod ( float $x , float $y );   
It is used to return the floating point remainder of the division of the argument.
1. <?php  
2. $x = 7;  
3. $y = 2;  
4. echo "Your Given Nos is : $x=7, $y=2"  
By using 'fmod()' Function your value is:1
5. $result ="By using 'fmod()' Function your value is:".fmod($x,$y);  
6. echo $result;  
7. // $result equals 1, because 2 * 3 + 1 = 7  
8. ?>  
sqrt()

It is used to return the square root of a number.
base64 encode and decode function
The base64_encode() function is an inbuilt function in PHP which is used to Encodes data with MIME base64. MIME (Multipurpose Internet Mail Extensions) base64 is used to encode the string in base64. The base64_encoded data takes 33% more space then original data.
used to convert to 64 numeric method
R2Vla3Nmb3JHZWVrcw== 
<?php 
  
// Program to illustrate base64_encode() 
// function 
$str = 'GeeksforGeeks'
  
echo base64_encode($str); 
?> 
<?php 
  
GeeksforGeeks
// Program to illustrate base64_decode() 
// function 
$str = 'R2Vla3Nmb3JHZWVrcw=='
  
echo base64_decode($str); 
?> 
r

No comments:

Post a Comment