PHP Program to convert kilometers to miles

It is a simple mathematical program in PHP to convert user input value in kilometers into equivalent miles. We recommend you go through the following topics for a better understanding of the program

How to convert kilometers to miles?

In this program, we are converting the kilometers into miles. To convert km to miles we have to multiply the value of km by 0.621371. For example, if the entered kilometer is 10 then the equivalent miles will be 6.21371

How to convert the kilometer to miles using PHP?

To convert the km to miles we first have to read the km into a variable km. After that, we must assign the value 0.621371 to a variable then to calculate the miles we must get the product of km and and store the result in the variable miles after that we can print the value of the variable miles as the miles equivalent to the entered km.


Step 1: Accept the value of kilometer into the variable km

Step 2: Assign the value 0.621371 into the variable m

Step 3: Assign the computed value of 'km * m' into the variable miles

Step 4: Print the value of the variable miles as the miles equivalent to the entered kilometer

PHP Source Code

$km = readline("Enter the KM: ");
$m = 0.621371;
$miles = $km * $m;
echo "$km Km is equal to $miles miles";


Enter the KM: 56
56 Km is equal to 34.796776 miles