PHP evaluating the content of an array -


i trying evaluate content of array. array contain water temperatures submitted user.

the user submits 2 temperaures, 1 hot water , 1 cold water.

what need evaluate both array items find if within limits, limits "hot water: between 50 , 66", "cold water less 21".

if either hot or cold fail check flag status "1" or if both pass check flag status "0".

below code working with:

$row_watertemp['hotmin'] = "50"; $row_watertemp['hotmax'] = "66";  $seqwaterarray new(array);  $seqwaterarray = array("58", "21");   foreach($seqwaterarray $key => $val) {     $fields[] = "$field = '$val'";     if($key == 0) {          if($val < $row_watertemp['hotmin'] || $val > $row_watertemp['hotmax']) {             $status = 1;             $waterhot = $val;         } else {             $status = 0;             $waterhot = $val;         }      }      if($key == 1) {         if($val > $row_watertemp['coldmax']) {             $status = 1;             $watercold = $val;         } else {             $status = 0;             $watercold = $val;         }     }     } 

my question is:

when run script array key(0) works when array key(1) evaluted status flag key(1) overrides status flag key0. if can great. many time.

it seems ok me, exept values @ limit, , can simplify

$row_watertemp['hotmin'] = "50"; $row_watertemp['hotmax'] = "66";  $seqwaterarray = array("58", "21"); $status = array() ;  foreach($seqwaterarray $key => $val) {     if($key == 0) {          $status = ($val >= $row_watertemp['hotmin'] && $val <= $row_watertemp['hotmax']) ;         $waterhot = $val;     } else if($key == 1) {         $status += ($val >= $row_watertemp['coldmax']) ;         $watercold = $val;     } } 

if 1 fails, $status = 1, if 2 tests failed, $status = 2, if it's ok, $status = 0.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -