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

Get data from a sub-array with json and php

I would like to obtain the value of "single_img" that is in a subarray but I can’t find the way

$video ='{"msg":"OK","server_time":"2021-12-04 20:33:26","status":200,"result":[{"single_img":"8eybbqf5nnta6vcw.jpg","file_code":"vg1fkuag1tsa","splash_img":"8eybbqf5nnta6vcw.jpg","canplay":1,"views":"0","length":"2370","uploaded":"2021-12-04 13:28:35","title":"(Hands On Ed Class \/ 12.04.2021)"}]}';

$do = json_decode($video);

echo json_encode($do);
 
$result= json_encode($do->result);

echo json_encode($result->single_img);

I appreciate your answers

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

>Solution :

you can decode the string as an associative array and access your key:

$video ='{"msg":"OK","server_time":"2021-12-04 20:33:26","status":200,"result":[{"single_img":"8eybbqf5nnta6vcw.jpg","file_code":"vg1fkuag1tsa","splash_img":"8eybbqf5nnta6vcw.jpg","canplay":1,"views":"0","length":"2370","uploaded":"2021-12-04 13:28:35","title":"(Hands On Ed Class \/ 12.04.2021)"}]}';

$do = json_decode($video, true);

var_dump($do['result'][0]['single_img']);
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