title: How to get array items in PHP/Wordpress
body: <p>Hi I have this following code to get shipping methods from WooCommerce. </p>
  
  <pre><code>        global $woocommerce;
          $cart = wc()-&gt;cart-&gt;get_shipping_packages();
          $sm =  wc()-&gt;shipping-&gt;calculate_shipping_for_package($cart);
  
          return $sm;
  </code></pre>
  
  <p>and the result will return me an array like this:</p>
  
  <p><a href="https://i.stack.imgur.com/ZdpDQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZdpDQ.png" alt="enter image description here"></a></p>
  
  <p>how do I foreach it to get the data from rate array? and the value I want are id,label and method_id?</p>
  
  <p>print_r($sm); exit;</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [contents] =&gt; Array
                  (
                  )
  
              [contents_cost] =&gt; 0
              [applied_coupons] =&gt; Array
                  (
                  )
  
              [user] =&gt; Array
                  (
                      [ID] =&gt; 1
                  )
  
              [destination] =&gt; Array
                  (
                      [country] =&gt; SG
                      [state] =&gt; 
                      [postcode] =&gt; 
                      [city] =&gt; 
                      [address] =&gt; 
                      [address_2] =&gt; 
                  )
  
          )
  
      [rates] =&gt; Array
          (
              [international_delivery] =&gt; WC_Shipping_Rate Object
                  (
                      [id] =&gt; international_delivery
                      [label] =&gt; International Flat Rate
                      [cost] =&gt; 10
                      [taxes] =&gt; Array
                          (
                          )
  
                      [method_id] =&gt; international_delivery
                  )
  
              [table_rate-5 : 7] =&gt; WC_Shipping_Rate Object
                  (
                      [id] =&gt; table_rate-5 : 7
                      [label] =&gt; Registered Mail
                      [cost] =&gt; 0
                      [taxes] =&gt; Array
                          (
                          )
  
                      [method_id] =&gt; table_rate
                  )
  
              [table_rate-5 : 8] =&gt; WC_Shipping_Rate Object
                  (
                      [id] =&gt; table_rate-5 : 8
                      [label] =&gt; Non-Registered Mail
                      [cost] =&gt; 0
                      [taxes] =&gt; Array
                          (
                          )
  
                      [method_id] =&gt; table_rate
                  )
  
              [table_rate-5 : 9] =&gt; WC_Shipping_Rate Object
                  (
                      [id] =&gt; table_rate-5 : 9
                      [label] =&gt; Courier
                      [cost] =&gt; 0
                      [taxes] =&gt; Array
                          (
                          )
  
                      [method_id] =&gt; table_rate
                  )
  
          )
  
  )
  </code></pre>