Home > Software design >  For each unless the last one
For each unless the last one

Time:01-30

Hello how can I take only the first 6 and the last one be in another div

     $daysOfWeek = 
 array('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche');
 foreach($daysOfWeek as $day) {
      $calendar .= "<th class='header'>$day</th>";
 } 

CodePudding user response:

this will help you. you will need php version 7.3 minimum:

foreach($array as $key => $val) {
    if($key === array_key_first($array)) {
        // first
    }
    if($key === array_key_last($array)) {
        // last
    }
}
  •  Tags:  
  • Related