PHP中if条件中的&&运算符出现问题?

i am facing problem in my if condition if PHP code.i am using the && operator to validate both the conditions for image height and width but it only checks the first condition.

list($width, $height) = getimagesize('abc.jpg');

     if($width < 400 && $height < 200){

//do some thing }

 but it only validate the image width.

any hint??

The && operator is a lazy bastard. If the leftmost operation returns false, it does not feel the need to check any further. So, I'd say your image is 400 (or more) pixels in width, which means the height naturally will never be checked.

It should work like this:

if ($info = getimagesize("abc.jpg")) {
    if ($info[0] < 400 && $info[1] < 200) {
        // your code continues here...
    }
}

You can also write it in a more functional fashion (indexes go out):

if ($info = getimagesize("abc.jpg")) {
    if (current($info) < 400 && next($info) < 200) {
        // your code continues here...
    }
}

In any case, the getimagesize() function returns an array with more than two components, so that won't work.

Hope it helps :)