我的阵列:
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 ) )
我希望能够回显 [月份] 并且不重复它,但仍将其他值与正确的月份相关联。为了达到这一点,我做了一个 array_merge 将它们放在一起,就像你看到的那样。
它们分别看起来像这样:
#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 ) )
我已经尝试过 array_unique 但不起作用。我正在使用 foreach 语句来回显这些值。
谢谢你!
SQL 查询:
$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;
}
catspeake
一只甜甜圈