php - Change variable inside function foreach loop -


i've problem can't solve. think it's easy fix, after 3 hours of searching , trail-error. i've decided ask question on here:

this time function schedule application.

date_default_timezone_set('europe/amsterdam'); $current_time = time(); $unixtime = $current_time; $time = date("gi",$unixtime);  global $time;  function time_left($time, $active_class, $maxtime, $mintime){     if($time < $maxtime , $time > $mintime){                 global $active_class;         $active_class = 'active';         echo 'succes!';     } } 

here foreach loop, loop through array

foreach($rows $row){ switch($hours){  case 1:     $t = '8:45 - 9:15';     $mintime = 845;     $maxtime = 914;     time_left($time, $maxtime, $mintime);   break;  case 2:     $t = '8:45 - 9:15';     $mintime = 845;     $maxtime = 914;     time_left($time, $maxtime, $mintime);   break;    /* etc.. etc.. etc... */  }      echo "<li class='" . $active_class ."'>";   echo "<div class='right'></div>";   echo "<div class='hour'>", $times, "</div><span class='divider-time'>|</span>";    $hours++;   $i = 0;   foreach($row[$day] $r[1]){     $i++;     if ($i == 1) {       $class = 'vk';    } elseif ($i == 2) {    $class = 'lok';    } elseif ($i == 3) {    $class = 'doc';    }     echo "<span class='" . $class . "'>", $r[1],  "</span>";    }      echo "</li>";      $class++; } 

i 'succes!' echo on right location. active class not working properly. idea behind active class shown on 1 row. searches match , behind gets active class.

thanks in advanced.

you should restart $active_class variable in every iteration. otherwise, once set active won't change value again.

foreach($rows $row){     $active_class = '';      //your code here     .... } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -