Get positive value

abs() function returns the absolute value of its number argument

echo abs(-12.239);   //Prints: 12.34
echo abs(127);       //Prints: 127
Example returning the distance regardless of how the values are passed
function GetDistance($Start, $End)
{
  return abs($Start - $End);
}

GetDistance(-1, 4)   //Returns 5
GetDistance(4, -1)   //Returns 5
GetDistance(3, 7)    //Returns 4
GetDistance(7, 3)    //Returns 4
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *