Tutorial on how to convert meters into yards and feet with PHP

The following tutorial discusses how the metric unit meters can be converted into yards and feet with the help of PHP. Naturally enough these same conversion numbers can be used to perform the conversion in other programming languages.

Lets start of then with meters, and their conversion into yards. One meter is equal to 1.0936133 yards, meaning that if we multiply the number of meters times 1.0936133, we shall receive our result in yards. Here an example:

<?php

\$meters = 100;

\$yards = \$meters * 1.0936133;

echo \$yards." Yards";

?>

To convert yards to meters we have to turn this whole process around. Instead of multiplying meter by 1.0936133, we shall divide the number of yards by 1.0936133:

<?php

\$yards = 100;

\$meters = \$yards / 1.0936133;

echo round(\$meters, 2)." Meters";

?>

Moving on now to the conversion between meters and feet. Inside on meter there is room for 3.2808399 feet. Meaning that if we multiply the number of meters by 3.2808399 we shall receive the number of feet as a result:

<?php

\$meters = 100;

\$feet = \$meters * 3.2808399;

echo \$feet." Feet";

?>

Again the whole equations can be turned around to convert feet into meters by dividing the number of feet by 3.2808399:

<?php

\$feet = 100;

\$meters = \$feet / 3.2808399;

echo round(\$meters, 2)." Meters";

?>

And that is all there is to it! Note that the function round() was used on the last two example to round the numbers up to two decimal points. Other than that what you get is what you see!