title: According to what I know you cannot echo an array. You have to loop through it. Why are the values of my array printed?
body: <p>I have this data:</p>
  <pre><code>1CPT5
  
  'stock' =&gt; array (
    'warehouse' =&gt; 
    array (
      'warehouse_id' =&gt; 1,
      'name' =&gt; 'CPT',
    ),
    'quantity_available' =&gt; 5,
  )
  
  3JHB21
  
  'stock' = &gt; array (
    'warehouse' =&gt; 
    array (
      'warehouse_id' =&gt; 3,
      'name' =&gt; 'JHB',
    ),
    'quantity_available' =&gt; 21,
  )
  </code></pre>
  <p>and this code that is looping through the above data.</p>
  <pre><code>    foreach ($row['stock'] as $val) {
          foreach ($val['warehouse'] as $warehouse =&gt; $name) {
              echo $name;
          }
          echo $val['quantity_available'];
          echo '&lt;pre&gt;' . var_export($val, true) . '&lt;/pre&gt;';
      }
  </code></pre>
  <p>I am trying to display the quantity_available based on the ID of the warehouse (there are 2 warehouses) The first set of data is for warehouse_id 1 with name CPT and number of items 5.
  The second set of data is for warehouse_id 3 with name JHB and number of items 21.
  'warehouse' is an array and according to what I know you can only loop through an array, print_r or var_dump an array. Why if I then echo $name do I see all the values of the array and how do I isolate them so I can just get the id and based on the id display the quantity associated with that id?</p>
  <p>I finally figured it out and the following code displays the number I am after:</p>
  <pre><code>    foreach ($row['stock_at_takealot'] as $key =&gt; $val) {
  
          foreach ($val['warehouse'] as $key =&gt; $value) {
              if ($value == 1) {
                  echo $val['quantity_available'];
              }
          }
      };
  </code></pre>
  <p>but now I have another issue where all the values are displayed in one cell instead of two. What is my mistake here please?</p>
  <pre><code>    &lt;td class='small centerCol'&gt;&quot;;
      foreach ($row['stock_at_takealot'] as $key =&gt; $val) {
          foreach ($val['warehouse'] as $key =&gt; $value) {
              if ($value == 1) {
                  echo $val['quantity_available'];
              }
          }
      };
      &quot;&lt;/td&gt;
      &lt;td class='small centerCol'&gt;&quot;;
      foreach ($row['stock_at_takealot'] as $key =&gt; $val) {
          foreach ($val['warehouse'] as $key =&gt; $value) {
              if ($value == 3) {
                  echo $val['quantity_available'];
              }
          }
      };
      &quot;&lt;/td&gt;
      &lt;td class='small centerCol'&gt;&quot;
  </code></pre>