JSON_DECODE - get values from multidimensional array stdClass

How can I get the specific value from multidimensional array with stdClass object using json_decode ? For example, when I use $array['users'][16] in regular array, I will get the value for user with ID 16. How can I do this in case of JSON ?
0
give a positive ratinggive a negative rating
20 Jun 2021 at 12:10 PM
Hi,

You can get the values from stdClass Object multidimensional array in a similar way, than in case of standard array. What you need to do, is include true parameter into json_decode function.

For example:

$json_array = '{"users":{"10":"Abc", "16":"Abcde"}}';

$array = json_decode($json_array, true);

echo $array['users'][16];

0
give a positive ratinggive a negative rating
23 Jun 2021 at 10:25 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us