Webmaster Forum

Webmaster Forum (http://www.v7n.com/forums/index.php)
-   Coding Forum (http://www.v7n.com/forums/forumdisplay.php?f=16)
-   -   Walking through multidimensional json array with PHP (http://www.v7n.com/forums/showthread.php?t=427227)

poster 02-25-2018 09:39 PM

Walking through multidimensional json array with PHP
 
I need to access a large nested multidimensional array in json using PHP

So, in the example below I need to get to the ID at the very bottom, I can do it by using echo $myarray['Data']['Car']['Id']

but how do I access by key, e.g. ['Data'][0]['Id'] and how can I loop through all of the array values, if I am only interested in the Id value??

$myarray =

Array (

[Response] => Success
[Message] => Lorem Ipsum
[URL] => https://www.test.com
[BaseLinkUrl] => https://www.test.com
[Default] =>
Array (
[Desc] => 12345
[Known] => yes )
[Data] =>
Array (
[Car] =>
Array (
[Id] => 98333

etc...

wmtips 03-23-2018 06:43 AM

If you already converted JSON string to an array, you can iterate array items with code similar to this:

PHP Code:

foreach ($myarray['Data'] as $key=>$arr)
{
 echo 
$key.' = '.$arr['Id'].'<br />';




All times are GMT -7. The time now is 01:35 PM.

3.8.7