php - arrays into function inside foreach -


i have function i've been using set class in div in html. until loaded function on page load , ran variables through each time div called.

function setclass($flow, $low, $good) {    if ($flow <= $low)      return "tdy";     if ($flow <= $good)      return "tdg";     return "tdr";  } 

i hardcode $low , $good needed.

$low = (300);  $good =(450); $class = (setclass($flow[1], $low, $good)); 

and on , on , on. can imagine have rather long scripts done in 30 or 40 lines.

*edited *

the goal color coded css table. below second column yellow. in between 2nd , 3rd green. above 3rd red. perhaps own distorted logic , there simple , common solution.

i want put function inside loop , run array through it. have series of thresholds want loop through function. first column seperate array - flows second low threshold. third high threshold

in function below low returns tdy. less third column returns tdg greater returns tdr $flows low $flows[1] 1 3 $flows[2] 2 4 $flows[3] 3 5 $flows[4] 4 6 ...

for example:

    $flows[1] => 2     $flows[2] => 1     $flows[3] => 6     $flows[4] => 5 

i want loop numbers through function

and result array:

    [1] tdg     [2] tdy     [3] tdr     [4] tdg 

i think know you're after; run function each loop iteration:

foreach ($flo $i => $flo_item) {     $class = setclass($flo_item[2], $low, $good);     // use $riv[$i] , $class here } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -