在PHP中解析复杂的json对象[重复]

This question already has an answer here:

i have this scenario of having a mixed response from a server and i need to process its data in PHP

Array
(
    [14424174] => Array
        (
            [0] => Array
                (
                    [id] => 45
                    [nm] => This is a driver name
                    [ph] => 5454545
                )

        )

)

I want to access id, nm, ph values

but i had no luck cause this index number (14424174) is unknown to me, so i need to first store this index and then parse the array

</div>

Use a nested foreach():

foreach($arr as $i => $sub_arr)
{
   foreach($sub_arr as $sub_i => $sub_sub_arr)
   {
      $id = $sub_sub_arr['id'];
      $nm = $sub_sub_arr['nm'];
      $ph = $sub_sub_arr['ph'];
   }
}

You can use the following pattern:

foreach($array as $key=>$val) {
   //get the id:
   var_dump($key)//14424174
   $nm = $val[nm];
   $ph = $val[ph];
}