I am trying to calculate workers pay rate from their worked time. For example if workers go to each client house the number of hours or minutes or hours and minute they spent there, the rate will be calculated from a fixed pay rate($10).
Bellow is the code I was able to create
$varWorkHour = '00:30';
$varPayRate = 10.00;
$varWorkTime = 10.00;
if ($varWorkHour == '1:00') {
$varWorkTime = (100 / 100) * $varPayRate;
} else if ($varWorkHour == '00:45') {
$varWorkTime = (85 / 100) * $varPayRate;
} else if ($varWorkHour == '00:30') {
$varWorkTime = (50 / 100) * $varPayRate;
} else if ($varWorkHour == '00:15') {
$varWorkTime = (15 / 100) * $varPayRate;
}
echo $varWorkTime;
The code worked
But the problem is I don’t want to use if statement, as you can see the code is limited to 1 hour below and there are some cases where workers can work up to 5 hours and more. Using if statement on that will be exhausting.
Please how can I calculate the pay rate from worked time dynamically without using if statement.