How can PHP be used to calculate and display the cost per kilometer in a simple fuel consumption calculator?
To calculate and display the cost per kilometer in a simple fuel consumption calculator using PHP, you can first calculate the cost per kilometer by dividing the total cost of fuel by the total distance traveled. Then, you can display this calculated cost per kilometer to the user.
<?php
// Input values
$totalCost = 50; // Total cost of fuel
$totalDistance = 500; // Total distance traveled
// Calculate cost per kilometer
$costPerKm = $totalCost / $totalDistance;
// Display the cost per kilometer to the user
echo "Cost per kilometer: $" . number_format($costPerKm, 2);
?>