title: Access variable outside foreach loop PHP
body: <p>I'm new to PHP. Can anyone tell me how to access the foreach loop variable outside foreach. Please find below by code.</p>
  
  <pre><code>  &lt;?php  $categories = Mage::getModel('catalog/category')-&gt;getCollection()-&gt;addAttributeToSelect('*'); 
           foreach ($categories as $category): 
           $categorySize = $category-&gt;getSize_chart(); 
           print_r ($categorySize); 
           endforeach;
      ?&gt;
  </code></pre>
  
  <p>I need it in the following html img tag's src attribute.</p>
  
  <pre><code>&lt;div class="SizeChat"&gt;&lt;p&gt;close&lt;/p&gt;&lt;div class="Padd"&gt;&lt;img src="&lt;?php echo Mage::getBaseUrl('media').'catalog/category/'.$categorySize ?&gt;"&gt;&lt;/div&gt;&lt;/div&gt;
  </code></pre>