Function to Output Humidex "Description"
The following PHP code provides a function that outputs the "description" of the humidex value. It uses the array to provide the lookup for what needs to be compared.
Code: Select all
$SITE['humidexval'] = array(
"0" => array("0","29","Little or no discomfort"),
"1" => array("30","34","Noticeable discomfort"),
"2" => array("35","39","Evident discomfort"),
"3" => array("40","44","Intense discomfort; avoid exertion"),
"4" => array("45","0", "Dangerous discomfort"),
"5" => array("54","0", "Heat stroke probable") );
echo humidexDesc ($humidex) . "<br/>";
// Function returns the description that matches the
// Humidex value. Note that humidex is rounded to
// provide an int value.
function humidexDesc($invalue) {
global $SITE;
$compare = round($invalue);
$desc = "";
foreach( $SITE['humidexval'] as $key => $value) {
if ( $value[0] == 0 && $compare <= $value[1] ) {
$desc = $value[2];
}
if ( $value[1] == 0 && $compare >= $value[0] ) {
$desc = $value[2];
}
if ( ($value[0] != 0 && $value[1] != 0 ) &&
($compare >= $value[0] && $compare <= $value[1]) ) {
$desc = $value[2];
}
}
return ($desc);
}