How to convert kilograms or grams to pounds in php?

In this post, The function converter helps you convert grams, kilograms to pounds in PHP.

1. Code:

<?php
function convertWeightToLb($unit, $weight){
		switch (strtolower($unit)) {
			case "g":
				$conv = 0.00220462262;
				break;
			case "kg":
				$conv = 2.20462262;
				break;
			default:
				$conv = 1;
				break;
		}
		$weight = $weight * $conv;
		return $weight;
	}
	echo convertWeightToLb("g", 10000);
	echo "<br/>";
	echo convertWeightToLb("kg", 1);
?>

2. Example:

Input:

Input 1: Weight unit: kg , Weight = 1
Input 2: Weight unit: g , Weight = 10000

Output:

Output 1: 22.0462262
Output 2: 2.20462262