M. of CA
M. of CA

Reputation: 1546

PHP is_array returning false?

I have used is_array many times. The variable is an array, see my code, but when i use is_array function it returned false

Any Ideas?

Here is my code.

public function updateCategories($array = null)
{   
    echo gettype($array); // echos array
    if($array = null)
    {    
        return false;
    }    
    if(!is_array($array))
    {      
        echo "false"; // echos false
        return false;
    }

    foreach($array as $key => $val)
    {
        foreach($val as $Property => $Value)
        {
            if(!$this->updateCategoryProperty($key, $Property, $Value))
            {
                return false;
            }
        }
    }
}

Upvotes: 1

Views: 3682

Answers (2)

Stuck
Stuck

Reputation: 12292

Additionally to Russel Dias answer: always write your "null-checks" in this way:

if (null == $my_var)

now, if missing one "=", this will always get a real error, because you cannot assign something to null.

Upvotes: 1

Russell Dias
Russell Dias

Reputation: 73342

Your if($array = null) is not comparing, but assigning.

Upvotes: 13

Related Questions