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

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

autoload
Release: 2023-03-09 13:16:02
Original
4165 people have browsed it

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    )
Copy after login
  • $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>";
?>
Copy after login
输出:
4.2
5
5
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template