how to use if statements in php to echo out just one variable
I have this code below which outputs several values in kilometers after a computation. how can I limit it to bring out a single output given the condition that if $miles is less than 20km,it should echo “you will get a mechanic in an hours time”. here is the code:
$theta = $driver_long - $longitude->lng;
$dist = sin(deg2rad($driver_lat)) * sin(deg2rad($data3->lat)) + cos(deg2rad($driver_lat)) * cos(deg2rad($data3->lat)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515 * 1.609344 ."km";
echo "
<div class='form-group'>
<input type='text' value='".$miles."' disabled>
<input type='hidden' value='".$miles."' name='distance[]'>
</div>
";
if ($miles < 20){
echo "a mechanic would get to you in about an hour's time";
}elseif ($miles <40) {
echo "a mechanic would get to you in about an 2 hour's time";
}
else {
echo "no mechanic withing that location found";
}
?>
from Laravel Questions and Answers https://laravelquestions.com/laravel/how-to-use-if-statements-in-php-to-echo-out-just-one-variable/
via Lzo Media
No comments:
Post a Comment