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;
            }
        }
    }
}
link|improve this question

feedback

1 Answer

up vote 11 down vote accepted

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

link|improve this answer
WOOOOW i cant believe i missed that, i went over my code many times. Thank you very much. – M. of CA Jan 6 at 0:30
You're welcome :) – Russell Dias Jan 6 at 0:30
1  
Exactly. Your editor should have pointed that for you. I use Netbeans, and it gives me a warning when I do assignments inside if statements. You should try it. – Beto Aveiga Jan 6 at 0:40
That's a lot of upboats for something so trivial :o – Russell Dias Jan 6 at 0:51
3  
This is common mistake to avoid it write the if statement like this if(null == $array) so if you missed '=' php will throw syntax error – satrun77 Jan 6 at 0:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.