这是我在按日期为每个产品组选择 sum(amounts) 后得到的数组。当日期没有相应数量时,它显示为空。我需要将其显示为零。
Array
(
[2019-05-16] => Array
(
[0] => 499
)
[2019-05-17] => Array
(
[0] => 1998
)
[2019-05-18] => Array
(
[0] => 195
)
[2019-05-19] => Array
(
[0] => 1194
[1] => 999
)
)
但是输出应该是这样的,
有没有办法将空值设为 0
Array
(
[2019-05-16] => Array
(
[0] => 499
[1] => 0
)
[2019-05-17] => Array
(
[0] => 1998
[1] => 0
)
[2019-05-18] => Array
(
[0] => 195
[1] => 0
)
[2019-05-19] => Array
(
[0] => 1194
[1] => 999
)
)
这是脚本
foreach ($productid as $itemid) {
$query1 = "select date, SUM(amount) as amount from app_product_details where date between '2019-05-14 00:00:00' and '2019-05-20 23:59:59' and appid = $itemid group by date";
$getquery1 = mysqli_query($conn,$query1);
while($getcount1 = mysqli_fetch_assoc($getquery1))
{
$grset1[] = $getcount1;
}
}
foreach($grset1 as $r){
$dates1[$r['date']][] = $r['amount'];
}
请帮助我达到输出。
守着星空守着你