Там есть пара недостающих подробностей о вашей структуре данных, и я не уверен, как ваши данные могут окупиться, поэтому я изготовлю недостающие части на основе опубликованных частей и предложу пару решений.
Код: ( Демо )
$results = (object)[
(object)[
"totals_grouped_by" => "day",
"totals" => (object)[
"2018-05-25" => (object)[
"sales" => "0.00", "orders" => 0, "items" => 0, "tax" => "0.00", "shipping" => "0.00", "discount" => "0.00", "customers" => 0
],
"2018-05-26" => (object)[
"sales" => "0.00", "orders" => 0, "items" => 0, "tax" => "0.00", "shipping" => "0.00", "discount" => "0.00", "customers" => 0
],
"2018-05-27" => (object)[
"sales" => "0.00", "orders" => 0, "items" => 0, "tax" => "0.00", "shipping" => "0.00", "discount" => "0.00", "customers" => 0
]
]
]
];
foreach($results as $val) {
echo "Proof of mostly-accurate multi-dimensional array structure: " , $val->totals_grouped_by;
}
echo "\n---\n";
// Loop the first level, then loop the totals level
foreach ($results as $val) {
foreach ($val->totals as $date => $subarray) {
echo "Showing $date: ";
var_export($subarray);
echo "\n";
}
}
// or assuming all levels are objects and you only want the one "totals" object that you posted:
echo "\n---\n";
foreach ($results->{0}->totals as $date => $subarray) {
echo "Showing $date: ";
var_export($subarray);
echo "\n";
}
Выходы:
Proof of mostly-accurate multi-dimensional array structure: day
---
Showing 2018-05-25: stdClass::__set_state(array(
'sales' => '0.00',
'orders' => 0,
'items' => 0,
'tax' => '0.00',
'shipping' => '0.00',
'discount' => '0.00',
'customers' => 0,
))
Showing 2018-05-26: stdClass::__set_state(array(
'sales' => '0.00',
'orders' => 0,
'items' => 0,
'tax' => '0.00',
'shipping' => '0.00',
'discount' => '0.00',
'customers' => 0,
))
Showing 2018-05-27: stdClass::__set_state(array(
'sales' => '0.00',
'orders' => 0,
'items' => 0,
'tax' => '0.00',
'shipping' => '0.00',
'discount' => '0.00',
'customers' => 0,
))
---
Showing 2018-05-25: stdClass::__set_state(array(
'sales' => '0.00',
'orders' => 0,
'items' => 0,
'tax' => '0.00',
'shipping' => '0.00',
'discount' => '0.00',
'customers' => 0,
))
Showing 2018-05-26: stdClass::__set_state(array(
'sales' => '0.00',
'orders' => 0,
'items' => 0,
'tax' => '0.00',
'shipping' => '0.00',
'discount' => '0.00',
'customers' => 0,
))
Showing 2018-05-27: stdClass::__set_state(array(
'sales' => '0.00',
'orders' => 0,
'items' => 0,
'tax' => '0.00',
'shipping' => '0.00',
'discount' => '0.00',
'customers' => 0,
))