I will be getting from an android app json code which will need to be inserted into a MySQL database.
{"androidID":"6e5d819af1afb92d","cardAmount":7.149999999999999,"cashAmount":10.0,
"list":[{"barcode":"1111117971111 5010018003165","cat_id":23,"cost":1.45,"id":0,"name":"1.45 CAN","payment_id":"","payment_type":"","product_id":2695,"product_type":"","qty":1,"staff_name":"","total":1.45},
{"barcode":"5054267000704 5054267000681 5449000125019 5449000124999 5038512005041 1111111141159 50271511 5449000107077 5038512000756 40822938 54492493 54493957","cat_id":23,"cost":1.85,"id":0,
"name":"1.85 BOTTLE","payment_id":"","payment_type":"","product_id":2694,"product_type":"","qty":1,"staff_name":"","total":1.85},
{"barcode":"54491496 5000112628739","cat_id":23,"cost":1.95,"id":0,"name":"500ml Diet Coke","payment_id":"","payment_type":"","product_id":1758,"product_type":"","qty":1,"staff_name":"","total":1.95},
{"barcode":"1211111111111","cat_id":6,"cost":6.7,"id":0,"name":"WAFFLE 3 SCOOP","payment_id":"","payment_type":"","product_id":1254,"product_type":"","qty":1,"staff_name":"","total":6.7},
{"barcode":"1111111111160","cat_id":6,"cost":5.2,"id":0,"name":"WAFFLE 2 SCOOP","payment_id":"","payment_type":"","product_id":1252,"product_type":"","qty":1,"staff_name":"","total":5.2}],
"paymentID":8646434759308,"paymentType":"Split"}
Using PHP 8 I am struggling with how to obtain all the data in a usable format.
What I need to do is get the first values androidID, cardAmount and cashAmount and then split the list by each product so from barcode to total.
Have tried various google search solutions using foreach loops but that either only returns the first 3 values and nothing from the list section or throws an error.
I did come across the following which will decode the entire lot but again struggling to then split the results as I cannot seem to access the array of information for each product.
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json_output, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $key => $value)
{
print $key . " : " . $value . "<br/>";
}
Further more the above json is an example. It may have 3 products in the list section it may have 1,2,5,10
What I need to achieve is get the data, determine how many products are in the list section and then insert those products into the database.
Would appreciate any pointers in the right direction or even if a no that's not possible with the json output in its current format.