PHP: Assigning values to a variable inside IF statement

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-05-04T21:35:49Z Indexed on 2010/05/04 21:38 UTC
Read the original article Hit count: 280

Hi guys, I was wondering if i could assign values to a variable inside an IF statement. My code is as follows:

<?php
    if ((count($newArray) = array("hello", "world")) == 0) {
        // do something
    }
?>

So basically i want assign the array to the $newArray variable, then count newArray and check to see if it is an empty array.

I know i can do this on several lines but just wondered if i could do it on one line

Thanks M

© Stack Overflow or respective owner

Related posts about php5

Related posts about arrays