How can you calculate the total price by multiplying the price and quantity for each item in a PHP array?

To calculate the total price by multiplying the price and quantity for each item in a PHP array, you can loop through the array and perform the multiplication for each item. You can then sum up the results to get the total price.

// Sample array of items with price and quantity
$items = [
    ['name' => 'Item 1', 'price' => 10, 'quantity' => 2],
    ['name' => 'Item 2', 'price' => 15, 'quantity' => 3],
    ['name' => 'Item 3', 'price' => 20, 'quantity' => 1]
];

$totalPrice = 0;

foreach ($items as $item) {
    $totalPrice += $item['price'] * $item['quantity'];
}

echo "Total Price: $" . $totalPrice;