|
He practises with the functions |
|
|
|
It realizes a function that it transforms from centimeters to inches and vice versa. The function must operate thus:
I throw distance (0.39, "cm");//If we make "cm" of that time it turns from inches to centimeters
2.54 threw distance ("inch");//If we set "inch" then it turns from centimeters to inches.
If we do not put anything in the second parameter, I throw distance (0.39); it must turn to centimeters.
1 inch = 2.54cm
To see Solution.
<? php
function it distances ($dis, $tipo ='cm') {
if ($tipo == "cm") {
return $dist*2.54;
} else if ($tipo == "inch") {
return $dis/2.54;
} else {
return "Error";
}
}
?>
|