I've got this array that gets created using jquery and is passed to a php script. It's json that gets decoded using json_decode. I can loop through most of it, but there's a part near the items bit that gets me stuck. Can you help?
This is output using print_r();
Array
(
[0] => Invoice
)
Array
(
[0] => Array
(
[Invoice] => Array
(
[header] => Array
(
[date] => 20-Jan-2020
[buyer] => Buyer 1
[order] => 006896
)
[items] => Array
(
[0] => Array
(
[name] => Name 1
[quantity] => Quantity 1
[rate] => 199.99
)
[1] => Array
(
[name] => Name 2
[quantity] => Quantity 2
[rate] => 99.99
)
)
)
)
[1] => Array
(
[Invoice] => Array
(
[header] => Array
(
[date] => 10-Jan-2020
[buyer] => Buyer 2
[order] => 007033
)
[items] => Array
(
[0] => Array
(
[name] => Item A
[quantity] => 25
[rate] => 19.99
)
[1] => Array
(
[name] => Item B
[quantity] => 30
[rate] => 29.99
)
)
)
)
)
PHP
$data = json_decode($_POST['data'],true);
echo '<pre>';
foreach ($data as $key=>$a) {
//print_r($key);print_r($a);
foreach ($a as $key=>$b) {
//print_r($key);print_r($b);
foreach ($b as $key=>$c) {
print_r($key);print_r($c);
foreach ($c as $key=>$d) {
//print_r($d);
}
}
}
}
echo '</pre>';
I'm trying to get the output as follows:
date 20-Jan-2020
buyer Buyer 1
order 006896
name Name 1
quantity Quantity 1
rate 199.99
name Name 2
quantity Quantity 2
rate 99.99
