Home > Backend Development > PHP Tutorial > How to use abs function in php

How to use abs function in php

藏色散人
Release: 2023-04-06 18:38:01
Original
3579 people have browsed it

Usage of abs function in php: [abs(number)]. The abs function is used to return the absolute value of the specified parameter. If the parameter is of float type, the returned type is also float, otherwise it returns the Integer type.

How to use abs function in php

#php How to use abs function?

(Recommended tutorial: php video tutorial)

The function of the abs() function is to return the absolute value of a number. The syntax is abs(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).

abs() function function: The function of abs() function is to return the absolute value of a number.

Syntax:

abs(number)
Copy after login

Parameters:

number must be a number.

Description: Return the absolute value of the parameter. If the parameter is float, the returned type is also float. If the parameter is int, the return type is int. If the parameter is a string string, 0 is returned;

php abs() function usage example:

<?php
$i = -100;
$j = abs($i);
$a = 6.7;
$b = abs($a);
$k = "hello world";
$c = abs($k);
echo $j."*****".$b."*****".$c;
?>
Copy after login

Output:

100*****6.7******0
Copy after login

Related recommendations: php training

The above is the detailed content of How to use abs function 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