Aşağıda gelen verileri ekrana yazdıracak şekilde formatlıyorum fakat burada hataları açınca undefined index hataları geliyor foreach içinde döngülerde if else kullanarak önüne geçmek mümkün ama bu durumda da çok fazla gereksiz kod bloğu oluşuyor.
$rows = array();
$total = array();
$stores = array();
foreach ($resultData as $item) {
$rows[$item['hour']]['total_orders'] += 1;
$total['total_orders'] += 1;
$rows[$item['hour']][$item['code']] += $item['order_total'];
$rows[$item['hour']]['all'] += $item['order_total'];
$total[$item['code']] += $item['order_total'];
$total['all'] += $item['order_total'];
if (!array_key_exists($item['store_code'], $item)) {
$stores[$item['code']] = $item['name'];
}
}
return array(
"rows" => $rows,
"total" => $total,
"list" => $stores
);
Hata kodları
Notice: Undefined index: 14 in
/Dosya.php on line
205 Notice: Undefined index: total_orders in
/Dosya.php on line
205 Notice: Undefined index: total_orders in
/Dosya.php on line
206 Notice: Undefined index: 3 in
/Dosya.php on line
207 Notice: Undefined index: all in /Dosya.php on line 207 Notice: Undefined index: all in
/Dosya.php on line
208 şeklinde devam ediyor.