Hi There,
I am going to paste php code; which consist of 2 IF Statements and 3 Switch statements and ONLY one to be true out of 5 statements;
I am sure, that I can get idea from good programmers to make it shorter to a function or class to get the same result in short and more precise code;
I will really appreciate if someone can make a function or class or any other shorter logic for this piece of code;
// $journey could be Oneway/Return
// $duration could be anything over 0 to 99
// $driving_hours is Integer anything over 0
if($journey == "Oneway") {
switch($driving_hours) {
case ($driving_hours <= 4.5):
$type = "S/Half Day";
$driver = 1;
break;
case(($driving_hours >=4.6) && ($driving_hours<=9)):
$type = "S/Full Day";
$driver = 1;
break;
case(($driving_hours >=9) && ($driving_hours <=21)):
$type = "S/Double";
$driver =2;
break;
case($driving_hours > 21):
$type = "S/Over 21hrs";
$driver = 2;
break;
}
}
else {
if($duration <=21) {
switch($duration) {
case (($duration <= 4.5) && ($driving_hours <=4.5)):
$type = "R/Half Day";
$driver = 1;
break;
case (($duration <= 9) && ($driving_hours <=9)):
$type = "R/Full Day";
$driver =1;
break;
case (($duration <= 21) && ($driving_hours <=9)):
$type = "R/Full Day/O";
$driver = 1;
break;
case (($duration <= 21) && ($driving_hours >= 9)):
$type = "R/DOUBLE";
$driver = 2;
break;
}
}
else {
switch($duration) {
case (($duration >= 21) && ($driving_hours <=4.5)):
$type = "R/HDD/";
$driver = 1;
break;
case (($duration >= 21) && ($driving_hours <=9)):
$type = "R/FDD";
$driver = 1;
break;
case (($duration >= 21) && ($driving_hours >=9)):
$type = "R/DDD";
$driver = 2;
break;
}
}
}