• 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 Convert Radians to Degrees with php rad2deg() Function

php Convert Radians to Degrees with php rad2deg() Function

February 5, 2022 Leave a Comment

To convert radians to degrees for use in trigonometric functions in php, the easiest way is with the php rad2deg() function.

$degrees = rad2deg(pi()/2)

The php collection of math functions has many powerful functions which make performing certain calculations in php very easy.

One such calculation which is very easy to perform in php is converting radians to degrees.

We can convert radians to degrees easily with the php rad2deg() function.

To do so, we need to pass any number to the php rad2deg() function.

Below are a few examples of how to use the rad2deg() function to convert different angles, in radians, to degrees with in php.

echo rad2deg(0);
echo rad2deg(pi()/6);
echo rad2deg(pi()/3);
echo rad2deg(pi()/2);

// Output:
0
30
60
90

If you’d like to go the other way, converting degrees to radians, you can use the deg2rad() php function.

Converting Radians to Degrees Without the rad2deg() function in php

Converting radians to degrees is a very easy formula. To convert radians to degrees, all we need to do is multiply the degrees by 180 and divide by pi.

We can convert radians to degrees without the help of the math module easily in php.

Below is a user-defined function which will convert radians to degrees for us in our php code.

function radians_to_degrees(float $radians) {
  return $radians * (180/pi());
}

Let’s test the function to verify that we get the same results as the rad2deg() php function.

function radians_to_degrees(float $radians) {
  return $radians * (180/pi());
}

echo radians_to_degrees(0);
echo radians_to_degrees(pi()/6);
echo radians_to_degrees(pi()/3);
echo radians_to_degrees(pi()/2);

// Output:
0
30
60
90

As you can compare for yourself to the example above, we get the same results as using rad2deg()

Hopefully this post was helpful for you to learn how to convert radians to degrees in php with and without the rad2deg() php function.

Other Articles You'll Also Like:

  • 1.  php min – Find Minimum Value of Array in php
  • 2.  php max – Find Maximum Value of Array in php
  • 3.  php Absolute Value with abs Function
  • 4.  php str_replace – Replace String in php
  • 5.  php array_combine() – Create New Array Given Arrays of Keys and Values
  • 6.  php var_dump() Function – Print Information about Variable Type and Value
  • 7.  php strlen() – Get the Length of String Variable in php
  • 8.  php Delete Files with php Unlink Function
  • 9.  Remove HTML Tags from String in php
  • 10.  echo php – Output One or More Strings

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