How to convert inch or meter to centimeter in PHP?
In this post, we use this calculation tool to convert quickly and easily between inches and centimeters , meter in PHP.
1. Code:
<?php function convertLengthToCm($unit, $length){ if ("in" === strtolower($unit)) { // 1 inch = 2.54 cm $length = $length * 2.54; //$length = round($length, 2); } if ("m" === strtolower($unit)) { $length = $length * 100; } return $length; } $length = 8.5; echo convertLengthToCm("in", $length); echo '<br/>'; echo convertLengthToCm('m', $length); ?>
2. Example:
Input:
Input 1: length = 8.5 , unit = in Input 2: length = 8.5 , unit = m
Output:
Output 1: 21.59 cm Output 2: 850 cm