How to convert centimeter or ,meter to inch in PHP?

In this post, we use this calculation tool to convert quickly and easily between inches, centimeters and meter in PHP.

1. Code:

    <?php 
   function convertLengthToIn($unit, $length){
		if ("cm" === strtolower($unit)) {
			$length = $length * 0.393700787;
		}
		if ("m" === strtolower($unit)) {
			$length = $length * 39.3700787;
		}
		return $length;
	}
    $length = 8.5;
    echo convertLengthToIn("cm", $length);
	echo '<br/>';
    echo convertLengthToIn('m', $length);
    ?> 

2. Example:

Input:

Input 1: length = 8.5 , unit = cm
Input 2: length = 8.5 , unit = m

Output:

Output 1: 3.3464566895 in
Output 2: 334.64566895 in