Bot program to count the products bought in the supermarket, with total sum.
<?php $products_bought = array("cucumbers", "milk", "bread", "oil", "butter"); $products_prices = array(1.5, 2.5, 2, 1.5, 3); $total_sum = 0; function count_products($products_bought, $products_prices) { $counter = count($products_bought); $total_sum = 0; for ($i = 0; $i < $counter; $i++) { echo "Product $i : $products_bought[$i] - costs $products_prices[$i] \n"; $total_sum += $products_prices[$i]; } return $total_sum; } $total_sum = count_products($products_bought, $products_prices); echo "Total cost is $total_sum"; ?>