title: How can I loop through a JSON Object in PHP?
body: <p>I have a variable <code>$arr</code> in PHP. It has the following data inside it.</p>
  
  <p>This is my PHP Code.</p>
  
  <pre><code>    $data = array(
          'Request' =&gt; 'StockStatus',
          'merchant_id' =&gt; 'shipm8',
          'hash' =&gt; '09335f393d4155d9334ed61385712999'
          );
  
      $url = 'https://ship2you.com/ship2you/';
  
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_PORT, 443);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      $result = curl_exec($ch);
      curl_close($ch);
  
      $arr = json_decode($result, true);
  
      foreach ($arr as $value) {
          echo $value['packagename'];
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/LfPkJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LfPkJ.png" alt="enter image description here"></a></p>
  
  <p>I want to loop through it. How can I achieve it? I tried using foreach but it gives me error. Thanks in advance.</p>