Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print the array value inside the json array in php

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading