Home  >  Article  >  Backend Development  >  Using abs() to obtain the absolute value of parameters in php

Using abs() to obtain the absolute value of parameters in php

autoload
autoloadOriginal
2021-05-07 11:35:074089browse

Using abs() to obtain the absolute value of parameters in php

In the last article, we introduced "Using stripos() in php to obtain the position of the first occurrence of a string". This article will take you to take a look. abs()Function. In the daily use of php, we may need to obtain the absolute value of a variable. At this time, we can use the built-in function abs() function in php , this article first takes you to take a look at the syntax of the function:

abs   ( mixed $number    )
  • $number: the numeric value to be processed.

  • Return value : The absolute value of $number. If the parameter $number is float, the return type is also float, otherwise it returns integer (because float usually has a larger value range than integer).

Code example:

<?php

$abs = abs(-4.2); 
$abs2 = abs(5);   
$abs3 = abs(-5);  
echo $abs."<br>";
echo $abs2."<br>";
echo $abs3."<br>";
?>
输出:
4.2
5
5

Recommendation: 2021 PHP interview questions summary (collection)》《 php video tutorial

The above is the detailed content of Using abs() to obtain the absolute value of parameters in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn