How to convert metres to feet and inches in PHP
During development of a web application we had to convert metres to feet and inches using PHP. Not having fully remembered the formula from school (day dreaming was just so much more fun), we turned to Google...
Surprisingly it is quite hard to find the formula to convert metres to feet and inches. Plenty of sites tell you the magic number of 3.28084 that you multiply metres by to get a decimal number of feet, but nothing easy for inches.
So here is a small PHP function for you:
function metresToFeet($metres){
$feet = floor($metres * 3.28084);
$inches = ($metres * 3.28084) - $feet;
$inches = intval($inches*12);
return "{$metres}m = {$feet}ft {$inches}in";
}
Enjoy the code snippet and feel free to tell us if you found it useful or used this code sample somewhere!
Share to your favourite website
Comments
One or more comments are waiting for approval by an editor.