How can PHP be utilized to automate the calculation of fuel surcharges and toll fees in an online shop shipping module?

To automate the calculation of fuel surcharges and toll fees in an online shop shipping module using PHP, you can create functions that take into account the necessary variables such as distance, fuel cost, and toll fees. These functions can then be called whenever shipping costs need to be calculated, streamlining the process and ensuring accurate pricing.

// Function to calculate fuel surcharge based on distance
function calculateFuelSurcharge($distance, $fuelCostPerMile) {
    return $distance * $fuelCostPerMile;
}

// Function to calculate toll fees based on toll rate per mile
function calculateTollFees($distance, $tollRatePerMile) {
    return $distance * $tollRatePerMile;
}

// Example of how to use the functions
$distance = 100; // Distance in miles
$fuelCostPerMile = 0.25; // Fuel cost per mile
$tollRatePerMile = 0.05; // Toll rate per mile

$fuelSurcharge = calculateFuelSurcharge($distance, $fuelCostPerMile);
$tollFees = calculateTollFees($distance, $tollRatePerMile);

echo "Fuel surcharge: $" . $fuelSurcharge . "\n";
echo "Toll fees: $" . $tollFees . "\n";