2 Replies - 178 Views - Last Post: 12 March 2014 - 06:28 AM Rate Topic: -----

#1 Raj-uk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-March 14

foreach loop

Posted 12 March 2014 - 03:17 AM

Hi there, its been 1 week cant find any help. how can we echo variable outside the loop WITH all the array value?


//////////
$sdate = '12-05-14';

$edate = '12-07-14';

function get_months($date1, $date2) { 
   $time1  = strtotime($date1); 
   $time2  = strtotime($date2); 
   $my     = date('n-y', $time2); 
   $mesi = array(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec); 
    
   //$months = array(date('F', $time1)); 
   $months = array(); 
   $f      = ''; 

   while($time1 < $time2) { 
      if(date('n-y', $time1) != $f) { 
         $f = date('n-y', $time1); 
         if(date('n-y', $time1) != $my && ($time1 < $time2)) { 
             $str_mese=$mesi[(date('n', $time1)-1)]; 
            $months[] = $str_mese."".date('y ', $time1); 
         } 
      } 
       $time1 = strtotime((date('Y-n-d', $time1).' +15days'));
   } 

   $str_mese=$mesi[(date('n', $time2)-1)]; 
   $months[] = $str_mese."".date('y', $time2); 
   return $months; 
} 


foreach(get_months($sdate,$edate) as $value){ 
 echo strtoupper($value); }
 echo get_months($sdate.$edate);



Is This A Good Question/Topic? 0
  • +

Replies To: foreach loop

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 575
  • View blog
  • Posts: 2,583
  • Joined: 03-December 12

Re: foreach loop

Posted 12 March 2014 - 04:33 AM

You can't, unless you are echoing EACH value, ie,

$
month = array('Jan', 'Feb', 'Mar');

echo $month[0];
echo $month[1];
...
..
.

Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3494
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: foreach loop

Posted 12 March 2014 - 06:28 AM

note that line #10 throws an "Undefined Constant" notice.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1