On 01/02/2013 10:21 AM, Marc Guay wrote:
Won't this type of condition/test always return true?

I simplified the example.  In my real life case the "foo" and "bar"
are variables which can be empty strings, and if they both are not, I
would like to display them.


Then why not use empty()?

$a = "foo";
$b = "bar";
if ( !empty($a) && !empty($b) ){
    echo $a."<br />".$b;

The reason I ask is that what if one of your strings was a "0" (zero) I would expect your code would not work as you had intended.

php -r 'if ( $a="foo" && $b="0" ) { echo "\n\n{$a}\n{$b}\n\n"; }'

In my testing, it does not. I would then have to ask, how often do you think a string will be "0"?

Jim Lucas


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to