Check array with null value, it returns me as value

  arrays, message, null, object, php

I make a query to the DB if the values ​​exist and if they don’t exist, I insert in DB, otherwise I need to throw an error message.
The problem is that the array of objects gets the null values ​​and interprets them to me as values, so it can’t send the message.
I tried empty (array), isset (array), count (array), sizeof (array), array == undefined, and array.length. Nothing works.

This is the code when create the array:

if(....){
} else {
    while ($row = $consulta->fetch()) {
        if($row['total'] == 0) {
            $this->rowsFinded = [
                "id" => $id,
                "da" => $da,
                "la" => $la,
                "lo" => $lo,
                "op" => $op,
                "loi" => $loi
            ];
        }
    }
}

return $this->rowsFinded;

When I can’t find the rows, the insertion is good. This is what I see with xdebug:

if (empty($rowsFinded) || !isset($rowsFinded) || is_null($rowsFinded)) {  //$rowsFinded: {[6], [6]}{2}

But when find the rows the result is an array with null values:

if (empty($rowsFinded) || !isset($rowsFinded) || is_null($rowsFinded)) {  //$rowsFinded: {[null], [null]}{2}

What is the problem? How can resolve this and show the message that this rows exists?

Thank you!

Source: Ask PHP

LEAVE A COMMENT