What is the correct formula to calculate net prices from an array of gross prices in PHP?

When calculating net prices from an array of gross prices in PHP, you need to subtract the tax amount from each gross price to get the net price. To do this, you can use a loop to iterate through the array of gross prices and apply the formula: net price = gross price / (1 + tax rate). This will give you the correct net price for each item in the array.

<?php
// Array of gross prices
$grossPrices = [100, 150, 200];
$taxRate = 0.20; // 20% tax rate

// Calculate net prices
$netPrices = [];
foreach ($grossPrices as $price) {
    $netPrices[] = $price / (1 + $taxRate);
}

// Output net prices
foreach ($netPrices as $netPrice) {
    echo "Net Price: " . $netPrice . "\n";
}
?>