• 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
  • 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.  How to Get Session ID in php with session_id()
  • 2.  php Move File from One Directory to Another Folder
  • 3.  Using strtoupper() in php to Convert String to Uppercase
  • 4.  php array_map() – Create New Array from Callback Function
  • 5.  php Trig – Using Trigonometric Functions in php for Trigonometry
  • 6.  php trim() Function – Remove Whitespace at Beginning and End of String
  • 7.  php max – Find Maximum Value of Array in php
  • 8.  Remove Specific Character from String Variable in php
  • 9.  Get Word Count of String in php with str_word_count() Function
  • 10.  php Random Number Generator with rand 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