function skyCoverage( $metarClouds ) {
foreach( $metarClouds[0] as $cloudReport ) {
$coverageCode = substr( $cloudReport, 0, 3 );
// I check $coverageCode here, and it is indeed "CLR"
switch( $coverageCode ) {
case "CLR":
$cloudCoverage = 0;
break;
case "FEW":
$cloudCoverage = 1/8;
break;
case "SCT":
$cloudCoverage = 3/8;
break;
case "BKN":
$cloudCoverage = 5/8;
break;
case "OVC":
$cloudCoverage = 8/8;
break;
}
$skyCoverage = $skyCoverage + $cloudCoverage;
}
// I check $skyCoverage here, and it is indeed 0
switch ( $skyCoverage ) {
case ( $skyCoverage >= 1.00 ):
$skyCondition = "Overcast";
// I do an echo $skyCoverage; here, and it actually spits out 0 still, even though it obviously shouldn't do anything at all
break;
case ( $skyCoverage >= 0.75 ):
$skyCondition = "Cloudy";
break;
case ( $skyCoverage >= 0.625 ):
$skyCondition = "Mostly Cloudy";
break;
case ( $skyCoverage >= 0.5 ):
$skyCondition = "Scattered Clouds";
break;
case ( $skyCoverage >= 0.375 ):
$skyCondition = "Partly Cloudy";
break;
case ( $skyCoverage >= 0.125 ):
$skyCondition = "Mostly Clear";
break;
case ( $skyCoverage < 0.125 ):
$skyCondition = "Clear";
break;
}
// $skyCoverage is still zero here
return $skyCondition;
// Somehow $skyCondition is "Overcast" with $skyCoverage = 0
}
Typically, more than one cloud layer is observed and, therefore, each $cloudCoverage
at the layer is added onto the other while looping through $metarClouds[0]
. However, if there is no cloud layer (clear, or "CLR"), then it should register as 0. And it does. However, the code somehow returns "Overcast".
I've checked both switch statements to ensure that "CLR" is being passed when I expect it is, and that $cloudCoverage
is equating to zero when I expect. It is, every time. And, $skyCoverage
still registers as zero just before the return.
I have tried setting $cloudCoverage
to 1-1, 0/1, 0.0, or some other method to ensure that PHP isn't somehow treating it as null and ... somehow ... processing it incorrectly. If I rewrite so that $cloudCoverage = 0.01
and pass CLR through the first switch, everything comes through the second switch correctly: Clear. I've also tried setting the last case to case 0:
etc., but still have the same erroneous result.