im trying to compare 4 variables so it must be look like this if ($a == $b and $c ==$d) or ($e==$f and $g==$h) but the result is always wrong
AND and OR are for boolean/bit comparison. This is probably what you want: if ($a == $b && $c ==$d) || ($e==$f && $g==$h) PHP:
Bit more than that, actually: if ( ( ( $a == $b ) and ( $c ==$d ) ) or ( ( $e==$f ) and ( $g==$h ) ) ) PHP: That works, but you actually MEAN: if ( ( ( $a == $b ) && ( $c ==$d ) ) || ( ( $e==$f ) && ( $g==$h ) ) ) PHP:
That's not at all true. The PHP operators 'and' and 'or' are identical to '&&' and '||' except that they have different association precedence. Most significantly for typical uses, '||' associates before assignment operators, while 'or' associates after them. For example, you can do: $stmt = mysql_query($query) or die(mysql_error()); Code (markup): and get the desired outcome (fall through and evaluate what's after the 'or' only if the assignment that comes before it evaluates as false) but if you tried to do: $stmt = mysql_query($query) || die (mysql_error()); Code (markup): then you'd get an undesired outcome because that is equivalent to: $stmt = (mysql_query($query) or die(mysql_error())); Code (markup): which would have a boolean result which makes $stmt useless. For bitwise comparisons you'd use the bitwise operators like '&' and '|'.