My array:
Array (
[0] => Array ( [month] => November [Average Purchase Price] => 2.52 [Total Purchase Gallons] => 84000 )
[1] => Array ( [month] => October [Average Purchase Price] => 2.615 [Total Purchase Gallons] => 63000 )
[2] => Array ( [month] => November [Average Customer Price] => 2.79 [Total Customer Gallons] => 25000 )
[3] => Array ( [month] => October [Average Customer Price] => 2.9050000000000002 [Total Customer Gallons] => 5500 ) )
I want to be able to echo out the [month] and not have it duplicated, but still associate the other values to the correct month. To get to this point I have done an array_merge to put them together like you see them.
Separately they look like this:
#1
Array (
[0] => Array ( [month] => November [Average Purchase Price] => 2.52 [Total Purchase Gallons] => 84000 )
[1] => Array ( [month] => October [Average Purchase Price] => 2.615 [Total Purchase Gallons] => 63000 ) )
#2
Array (
[0] => Array ( [month] => November [Average Customer Price] => 2.79 [Total Customer Gallons] => 25000 )
[1] => Array ( [month] => October [Average Customer Price] => 2.9050000000000002 [Total Customer Gallons] => 5500 ) )
I have tried array_unique and that does not work. I am using a foreach statement to echo out the values.
Thank you!
The SQL Queries:
$sql = "SELECT month, AVG(price) AS 'Average Purchase Price', SUM(gallons) as 'Total Purchase Gallons' from purchase_contracts
group BY month";
$purch = mysqli_query($con, $sql) or die(mysqli_error($con));
while ($rows = mysqli_fetch_assoc($purch))
{
$purch_items[] = $rows;
}
$sql1 = "SELECT month, AVG(price) AS 'Average Customer Price', SUM(gallons) as 'Total Customer Gallons' from customer_contracts
group BY month";
$cust = mysqli_query($con, $sql1) or die(mysqli_error($con));
while ($rows1 = mysqli_fetch_assoc($cust))
{
$cust_items[] = $rows1;
}