How can the provided PHP code be rewritten to function correctly?

The issue with the provided PHP code is that the variable `$total` is being used within the `calculateTotalPrice` function without being passed as an argument. To solve this, we need to pass `$total` as an argument to the function.

function calculateTotalPrice($price, $quantity, $total) {
    $total += $price * $quantity;
    return $total;
}

$total = 0;
$total = calculateTotalPrice(10, 2, $total);
echo "Total price: $" . $total;