take the absolute value of a number in php

To take the absolute value of a number in PHP, you can use the built-in abs() function. Here's an example:

main.php
$number = -5;
$absNumber = abs($number);
echo $absNumber; // outputs 5
71 chars
4 lines

In this example, we first create a variable $number and assign it the value of -5. We then use the abs() function to take the absolute value of $number and assign the result to a new variable $absNumber. We then use echo to output the value of $absNumber, which in this case is 5.

related categories

gistlibby LogSnag