i use the api to call the php page. this api have this json post data
{"product[]":["Layer Management System","Broiler Management System"]}
how can i get the data seprately for product[0]. i use this method
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data["product[]"];
but it was not woking and show the error below
<b>Notice</b>: Array to string conversion in
<b>/production/test_reg3.php</b> on line <b>8</b><br />
Array
and one more method is
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data["product[0]"];
it shows the error below
<b>Notice</b>: Undefined index: product[0] in
<b>/production/test_reg3.php</b> on line <b>8</b><br />
i need to store product[] value in any variable
help me with the good result thank your for spending your time for me
CodePudding user response:
It should be
$data["product[]"][0]
Don't get confused between the brackets which are part of the PHP syntax and the brackets which are part of the property name.