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

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • 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.  echo php – Output One or More Strings
  • 2.  php Convert Radians to Degrees with php rad2deg() Function
  • 3.  Replace Space with Dash in php String
  • 4.  Remove First Character from String Using php
  • 5.  What is the Difference Between unset() and unlink() in php?
  • 6.  php Rename File – Renaming Files and Directories Easily
  • 7.  Get Current Location Latitude Longitude in php
  • 8.  php range() – Create Array of Elements Within Given Range
  • 9.  php in_array – Check If Value is in php Array
  • 10.  Check if Variable Exists in php with isset() 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

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

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 © 2023 · The Programming Expert · About · Privacy Policy