I am working on a website where I have to show a table with several different climatic variables (max temperature, cloudiness, etc) in it for a given month chosen by the user. The basic table is separated by months and all I have to do is go fetch the data in the database and display it in the table.
There is also an other view where we display the same information, but for seasons instead of months. In order to do so, I have process the database information (whether it be take the maximum value out of the months of that season, the average of all the values for the months of that season, etc). In order to do that, I have separated all monthly values into different arrays, each containing the values for a given season. Then for each of those arrays, I call max() or min() in a switch() statement. Of course, to do that, I have to make sure that all the indexes of those arrays actually contain a value, and not the string "N/A" which I insert in them if for a given month there is no values in the database. So I do a check: if the array does not contain "N/A", then call the function (max() or min() etc), else just display "N/A".
The problem that I am having is that all the arrays that contain a float(0) in them will go in the else() statement, which I don't understand why because I am clearly doing my check on whether or not the array contains "N/A", not if it contains a NULL or empty string or 0. Why am I seeing this behavior?
For reference, here is my foreach() loop:
// The var_dump() are there so that I can see what is in my arrays, but will
// be removed when this issue is resolved.
foreach ($allSeasonsArray as $season)
{
echo "\n<td>\n";
switch($calculations[0])
{
case "MAX":
if (!in_array("N/A", $season))
{
echo max($season);
var_dump($season);
}
else
{
echo "N/A";
var_dump($season);
}
break;
case "MIN":
if (!in_array("N/A", $season))
{
echo min($season);
var_dump($season);
}
else
{
echo "N/A";
var_dump($season);
}
break;
case "MOY":
if (!in_array("N/A", $season))
{
echo round(array_sum($season) / count($season), 1);
var_dump($season);
}
else
{
echo "N/A";
var_dump($season);
}
break;
case "MED":
if (!in_array("N/A", $season))
{
echo round(median($season), 1);
var_dump($season);
}
else
{
echo "N/A";
var_dump($season);
}
break;
case "TOT":
if (!in_array("N/A", $season))
{
echo array_sum($season);
var_dump($season);
}
else
{
echo "N/A";
var_dump($season);
}
break;
default:
break;
}
echo "\n</td>\n";
}