• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / PHP / php Absolute Value with abs Function

php Absolute Value with abs Function

December 15, 2021 Leave a Comment

To find the absolute value of a number in php, the easiest way is with the php abs() function.

echo abs(-4); // Output: 4

Finding the absolute value of a number in php is easy. We can find the absolute number of both integers and floats using the php abs() function. The absolute value of a number is the non-negative value of a number.

If a positive number is passed to the abs() function, the return value is a positive number.

echo abs(3); // Output: 3

If a negative number is passed to the abs() function, the return value is a positive number.

echo abs(-13); // Output: 13

Finding the Absolute Value in php of an Integer

In php, we can use the abs() function to find the absolute value of an integer. The return value will also be of type integer.

echo abs(3); // Output: 3
echo abs(-3); // Output: 3

Finding the Absolute Value in php of a Float

In php, we can also use the abs() function to find the absolute value of a float. The return value will also be of type float.

echo abs(91.1237); // Output: 91.1237
echo abs(-91.1237); // Output: 91.1237

Hopefully this article has been helpful for you to understand how you can find the absolute value of a number in using php.

Other Articles You'll Also Like:

  • 1.  php print_r() Function- Get Information about Variables in php
  • 2.  Creating Custom category.php With Pagination
  • 3.  php array_fill() – Create Array of Length N with Same Value
  • 4.  php array_slice() – Get Slice of Elements from Array
  • 5.  How to Get Session ID in php with session_id()
  • 6.  Delete Cookie Using php
  • 7.  php switch case – How to Use Switch…Case Statements in php
  • 8.  Capitalize First Letter of String with php ucfirst() Function
  • 9.  Truncate Strings in php Using substr()
  • 10.  php acosh – Find Hyperbolic Arccosine of Number Using acosh() Function

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy