Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Check if 0?

I am using a class which returns me the value of a particular row and cell of an excel spreadsheet. To build up an array of one column I am counting the rows and then looping through that number with a for() loop and then using the $array[] = $value to set the incrementing array object's value.

This works great if none of the values in a cell are 0. The class returns me a number 0 so it's nothing to do with the class, I think it's the way I am looping through the rows and then assigning them to the array... I want to carry through the 0 value because I am creating graphs with the data afterwards, here is the code I have.

// Get Rainfall
$rainfall = array();
for($i=1;$i<=$count;$i++)
{
    if($data->val($i,2) != 'Rainfall') // Check if not the column title
    {
        $rainfall[] = $data->val($i,2);
    }
}

For your info $data is the excel spreadsheet object and the method $data->val(row,col) is what returns me the value. In this case I am getting data from column 2.

Screenshot of spreadsheet

like image 256
tarnfeld Avatar asked Feb 06 '26 02:02

tarnfeld


1 Answers

Did you try an array_push() ?

array_push($rainfall, $data->val($i,2));
like image 182
Philippe Avatar answered Feb 08 '26 16:02

Philippe