title: PHP - Return values of an array within and array
body: <p>I have an array with arrays in it:</p>
  
  <pre><code>Array (
    [0] =&gt; Array (
      [qty] =&gt; 2
      [name] =&gt; thing 1
      [model] =&gt; 70001
      [price] =&gt; 129.00
      [weight] =&gt; 75.00
      [id] =&gt; 139
    )
    [1] =&gt; Array (
      [qty] =&gt; 1 
      [name] =&gt; thing 2
      [model] =&gt; 70002
      [price] =&gt; 199.00
      [weight] =&gt; 45.00
      [id] =&gt; 53
    )
  )
  </code></pre>
  
  <p>I need to pull the weight of each product compare it to a MySQL DB (I can do this) multiply that by the qty and return a cost; then do the same to the next and so on.</p>
  
  <p>Final Update (with complete class function):</p>
  
  <pre><code>function quote($method = '') {
          global $order, $cart, $shipping_weight, $shipping_num_boxes;
  
          $order-&gt;delivery['postcode'] = strtoupper($order-&gt;delivery['postcode']);
          $order-&gt;delivery['postcode'] = str_replace (' ', '', $order-&gt;delivery['postcode']);
  
      foreach($order-&gt;products as $value){//loop through arrays within arrays
          $weight = $value['weight'];
          $qty = $value['qty'];
          $id = $value['id'];
  
          if($weight &lt;= 25)//find rate
              $weight_class = 'w25';
          elseif(25 &lt; $weight &amp;&amp; $weight &lt;= 50)
              $weight_class = 'w50';
          elseif(50 &lt; $weight &amp;&amp; $weight &lt;= 100)
              $weight_class = 'w100';
          elseif(100 &lt; $weight &amp;&amp; $weight &lt;= 150)
              $weight_class = 'w150';
          else
              $weight_class = 'w300';
  
          //strip postal code to fsa
          $postalcode = strtoupper(substr($order-&gt;delivery['postcode'],0,3));
          //query database for cost
          $postal_query = 'SELECT ' . $weight_class . ' FROM postal_codes WHERE fsa = "' . $postalcode . '"';
          $result = mysql_query($postal_query) or die(mysql_error());
  
          while($row = mysql_fetch_array($result)){
              $rate = $row[$weight_class].'&lt;br&gt;';
          }
          $cost = $rate * $qty;//multiple by number of products
          $shipping_total[$id] = $cost;//add total cost for this product(s) to array
      }
      $shipping_rate = array_sum($shipping_total);//sum array to total(s)
  
          $this-&gt;quotes = array(  'id' =&gt; $this-&gt;code,
                                  'module' =&gt; MODULE_SHIPPING_DLY3_TEXT_TITLE,
                                  'methods' =&gt; array(array(   'id' =&gt; $this-&gt;code,
                                                              'title' =&gt; MODULE_SHIPPING_DLY3_TEXT_WAY,
                                                              'cost' =&gt;  $shipping_rate)));
          if (tep_not_null($this-&gt;icon)) $this-&gt;quotes['icon'] = tep_image($this-&gt;icon, $this-&gt;title);
          if ($this-&gt;tax_class &gt; 0) {
              $this-&gt;quotes['tax'] = tep_get_tax_rate($this-&gt;tax_class, $order-&gt;delivery['country']['id'], $order-&gt;delivery['zone_id']);
          }
          return $this-&gt;quotes;
      }
  </code></pre>
  
  <p>I'll update if i figure out a way to reduce the number of queries..</p>
  
  <p>Jesse</p>