
-----------------------------------
vtruong
Fri Jul 23, 2010 12:52 pm

How does &amp;&amp; Operator Work in this code??
-----------------------------------
Hi guys! I am current learning PHP on my own and I have encountered one small problem! This is from a textbook accepting a HTML form and validating the users inputs with conditions. I do not have APACHE or PHP installed on my computer but I am still trying my best to learn this. The code is displayed below and I am confused on one of the last parts of the code...

if ($name && $email && $gender && $comments) {
      echo "Thank you, $name, for the following comments:
      $comments   
      We will reply to you at $email.\n";
      echo $message; // From the $gender conditional.
} 

If you can please help me explain how if ($name && $email && $gender && $comments) becomes true... when they're suppose to be $name is suppose to be a string, $email is a string, $gender is a string and $comments is a string. From my past experience of programming the && operator is only true in this case if $name, $email, $gender, $comments are exactly the same values.

Please let me know on how you guys think,
Thank you,
vtruong

P.S. here is the code! Thanks in advance!




   
Form Feedback


