Bojangles
Bojangles

Reputation: 101483

PHP logical AND of two variables

I'd like to do this:

$var = ($var2 . $var3)

This means $var is only true if $var1 and $var2 are truthy (anything that will cast to a boolean true).

Upvotes: 0

Views: 1409

Answers (3)

Diogo
Diogo

Reputation: 548

$var = isset( $var2 ) && isset( $var3 );

?

Upvotes: 1

shamittomar
shamittomar

Reputation: 46692

Do it like this:

 $var = ($var2 && $var3);

or simply like SQL:

 $var = ($var2 and $var3);

Read more about Logical Operators and how to use them at PHP manual. Both && and and operators are good enough for it, the only difference being the precedence.

Upvotes: 2

Gumbo
Gumbo

Reputation: 655239

. is the string concatenation operator. Use && for a boolean AND operation:

$var = $var2 && $var3;

Upvotes: 1

Related Questions