PHP absolute value : abs()

Using abs math function we can get absolute value of any number in PHP
Here are some examples
echo abs(-6.2); // Output 6.2
echo "<br>";
echo abs(-4); // Output 4
echo "<br>";
echo abs(3.2); // Output 3.2
echo "<br>";
echo abs(7); // Output 7
Here we are changing all negative numbers to positive numbers.

Changing all negative numbers of an array

We can take an array with both negative and positive numbers. We will use array_map() built in PHP function to change all negative elements to positive by using abs function.
$a= array(1,-2,4,-7.3,105); 
while (list ($key, $val) = each ($b)) { 
echo "$key -> $val <br>"; 
Output is here.
0 -> 1 
1 -> 2 
2 -> 4 
3 -> 7.3 
4 -> 105
pow() to get exponential value
Math Functions
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 All rights reserved worldwide Privacy Policy Disclaimer