Convert Fahrenheit to Celsius using Inline Calculation
If you only need to perform the conversion once or in a specific context, you can do the calculation inline without defining a separate function.
Example: Illustration of Calculating Fahrenheit to Celsius in PHP using inline calculations.
PHP
<?php $fahrenheit = 98.6; // Inline Calculation $celsius = ( $fahrenheit - 32) * 5 / 9; echo "{$fahrenheit}°F is = {$celsius}°C" ; ?> |
Output
98.6°F is = 37°C
Time Complexity: O(1)
Auxiliary Space: O(1)
PHP Program to Convert Fahrenheit to Celsius
Converting temperature from Fahrenheit to Celsius is a common task in many applications. The formula to convert Fahrenheit to Celsius is:-
Celsius = (Fahrenheit - 32) * 5/9
In this article, we will explore how to implement this conversion in PHP using different approaches such as inline calculations, functions, and using HTML.
Table of Content
- Using Inline Calculation
- Using a Function
- Through User Input using HTML