Answer the question
In order to leave comments, you need to log in
How to print all elements of an array from JSON?
How to loop through all elements of listProduct array from json in php?
{"idUser":1,"listProduct":[{"amount":5,"idProduct":2,"price":0.0,"weight":0.0}],"size":1}
<?php
$data = file_get_contents('php://input');
$json_data = json_decode($data , true);
$mysqli = new mysqli('localhost', 'db_user', 'db_pass', 'db_name');
$mysqli->set_charset('utf8');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($data == "" || empty($json_data['idUser']) || empty($json_data['listProduct'])) {
$response = array('status' => false, 'message' => 'Failure');
} else {
$idUser = (int) $json_data['idUser'];
foreach ($json_data as $key => $value) {
$message = $message." ". $value["amount"] . ", " . $value["idProduct"] . "<br>";
}
}
...
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question