How to convert a temperature from Celsius to Fahrenheit using php.

<?php
function celsiusToFahrenheit($celsius) {
    return ($celsius * 9/5) + 32;
}

$celsiusTemperature = 25;
$fahrenheitTemperature = celsiusToFahrenheit($celsiusTemperature);

echo "$celsiusTemperature°C is equal to $fahrenheitTemperature°F";
?>
  • The script defines a function celsiusToFahrenheit that takes a temperature in Celsius as input and converts it to Fahrenheit using the formula: F = C * 9/5 + 32.
  • The script then calls the function with a sample Celsius temperature ($celsiusTemperature) and prints the result.

Post your Answer