When I write
$char='a' if (!empty($char)){ echo 'true'; } else { echo 'false'; }
I believe, but when:
if ($char='a' && !empty($char)){ echo 'true'; } else { echo 'false'; }
Why am I getting a lie?
Because the second way is the same as:
if ($char = ('a' && !empty($char))){ echo 'true'; } else { echo 'false'; }
&& has higher priority than = , so $char will be false .
&&
=
$char
false
because you write if($char = 'a' && !empty($char)) , you use the assignment operator, use == , u should get the correct result.
if($char = 'a' && !empty($char))
==
Because of the single, there is one equal sign.
if ($char='a'
really
if ($char=='a'