title: Get the values of array using foreach loop
body: <p>I have an array received from android which has to be inserted to mysql table with fields user,product,remark,color,size,count.
  Im not able to get the values of inner loop data containing size and count.It shows error</p>
  
  <pre><code>$dat='[{"user":10,
          "product":58,
          "remarks":"ok",
          "details":[{
                   "color":"Red",
                   "data":[{
                          "size":12,
                          "count":1
                    },
                    {
                          "size":14,
                          "count":2
                    }]
           }]
      },
      {"user":10,
       "product":60,
       "remarks":"okk",
       "details":[{
                "color":"Black",
                "data":[{
                       "size":10,
                       "count":5
                       },
  
                ]},{
               "color":"Red",
               "data":[{
                     "size":10,
                     "count":3
                      },
  
                 ]}
        ]}
   ]';
  </code></pre>
  
  <p>This is the code i tried.</p>
  
  <pre><code>$s = json_decode($dat, true);
  print_r($s);
  
  
  foreach($s as $item)
  {
      foreach($item as $details) {
          foreach($details as $data) {
  
                  echo "user".$item['user'];
                  echo "product".$item['product'];
                   echo "remarks".$item['remarks'];
                   echo "color".$details['color'];
                  echo "size".$data['size'];
                  echo "count".$data['count'];
  
  
          }
      }
  }
  </code></pre>
  
  <p>This the output of <code>print_r($s)</code></p>
  
  <pre><code>Array(
          [0] =&gt; Array (
                   [user] =&gt; 10
                   [product] =&gt; 58 
                   [remarks] =&gt; ok
                   [details] =&gt; Array (
                               [0] =&gt; Array(
                                        [color] =&gt; Red
                                        [data] =&gt; Array ( 
                                                  [0] =&gt; Array (
                                                      [size] =&gt; 12
                                                      [count] =&gt; 1
                                                          ) 
                                                  [1] =&gt; Array (
                                                      [size] =&gt; 14 
                                                      [count] =&gt; 2 
                                                          ) 
                                                  )
                                      ) 
                               ) 
                   ) 
          [1] =&gt; Array (
                  [user] =&gt; 10 
                  [product] =&gt; 60 
                  [remarks] =&gt; okk 
                  [details] =&gt; Array ( 
                                  [0] =&gt; Array (
                                           [color] =&gt; Black 
                                           [data] =&gt; Array( 
                                                      [0] =&gt; Array ( 
                                                          [size] =&gt; 10 
                                                          [count] =&gt; 5 
                                                              ) 
                                                                                      ) 
                                           ) 
                                  [1] =&gt; Array( 
                                          [color] =&gt; Red 
                                          [data] =&gt; Array ( 
                                                      [0] =&gt; Array( 
                                                          [size] =&gt; 10 
                                                          [count] =&gt; 3 
                                                              ) 
                                                                                      ) 
                                          ) 
                                  ) 
                  ) 
          ) ;
  </code></pre>
  
  <p>Pls help me.Thanks in advance</p>