在PHP中使用带有JSON的foreach

I have a JSON file like this:

[
{
    "set_id": "10001",
    "name": "4x4 car",
    "img_url": "https://xxx.xxx.com/img/sets-b/10001.jpg",
    "parts": [
        {
            "part_id": "1001",
            "qty": "2",
            "color_id": "0",
            "type": 1
        },
        {
            "part_id": "1002",
            "qty": "2",
            "color_id": "0",
            "type": 1
        },
        {
            "part_id": "1003",
            "qty": "2",
            "color_id": "0",
            "type": 1
        },
        {
            "part_id": "1004",
            "qty": "2",
            "color_id": "0",
            "type": 1
        }
    ]
}
    ]

I am using PHP code like this:

 while($item = array_shift($json_output))
 {
    foreach ($item as $key => $value)
    {
        echo $key.' => '.$value."
";
    }
 }

But it returns the result:

set_id => 9398-1 descr => 4 x 4 Crawler set_img_url => https://img.rebrickable.com/img/sets-b/9398-1.jpg parts => Array

How do I want to return the parts info?

If you want only the parts

foreach ($item{"parts"] as $key => $value)
{
    echo $key.' => '.$value."
";
}

Sample here: http://sandbox.onlinephpfunctions.com If you want every 2 level property:

$items=json_decode($json,true);
foreach ($items as  $item) {

    foreach ($item as $key => $value)
    {
       if( is_array($value) ) { 

          foreach ($value as $subkey => $part)
          {
              foreach ($part as $partkey => $partvalue)
              {
                  echo $key .' '. $subkey . ' ['.$partkey.'] => '.$partvalue."
";
              }
          }
       } else {

        echo $key.' => '.$value."
";
       }
    }

}

Maybe you can use $array_json = json_decode($json_var, true) and then $parts = $array_json["parts"]; (I haven't execute the code, maybe has some errors)

http://php.net/manual/en/function.json-decode.php