Answers for "can you use foreach variable outside scope php"

PHP
1

php variable outside foreach

$categorySize = array();

<?php  $categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*'); 
         foreach ($categories as $category): 
         $categorySize = $category->getSize_chart(); 
         print_r ($categorySize); 
         endforeach;
    ?>

print_r($categorySize) //Now you can get it outside the loop
Posted by: Guest on August-25-2021
0

php variable outside foreach

$pages = get_pages();
$pagee = array();
foreach ($pages as $page) {
  $pagee[] = $page->post_title;
}
echo implode(",",$pagee);
Posted by: Guest on September-11-2021

Code answers related to "can you use foreach variable outside scope php"

Browse Popular Code Answers by Language