View Full Version : PHP Terms
08-15-2008, 07:10 AM
Hello everyone I would like to know the difference between using && and &
Also whats the difference between using || or | instead of && or &
One last thing: difference between == and =
Thank you for reading!
08-15-2008, 08:45 AM
Well from what I understand for the = sign at least, if you are using an if statement you would want to use ==, it won't work for =. But if you are making a string equal something use the single =.
if ($string ==)
$string = x
So the way I see it the double is a check to see, while the single makes it equal to.
08-15-2008, 10:56 AM
See the manual on operators (http://www.php.net/manual/en/language.operators.php), esp. bitwise (http://www.php.net/manual/en/language.operators.bitwise.php) vs. logical operators (http://www.php.net/manual/en/language.operators.logical.php) and assignment (http://www.php.net/manual/en/language.operators.assignment.php) vs. comparison operators (http://www.php.net/manual/en/language.operators.comparison.php).
Intresting, I thought the '||' , 'OR' - '&&' , 'AND' operators are the same !! but they dont.
08-17-2008, 12:31 AM
|| means OR. So like fish=water || fish=fins.
&& means AND (ALSO). So say if members id equals 12, && members membership equals active.
& is just a text character.
A single equal sign assigns a value =
Such as $name = "Bob"; now you assigned the variable $name to hold the information Bob.
A double equal == is to check if something is equal exactly the same.
If $name == "Bob". If its true it will process.
Also another one is != that means not equal to.
So if $name != "Bob" then it will process if the name is not bob.
08-17-2008, 02:33 AM
& - Bitwise AND
| - Bitwise OR
^ - Bitwise XOR
~ - Bitwise NOT
<< - Bitwise LEFT SHIFT
>> - Bitwise RIGHT SHIFT
= - Assign Right INTO Left
== - Comparative operator Left to Right
=== - Comparative operator Left to Right identical
|| - Logical OR
OR - Logical OR (lower precedence priority)
&& - Logical AND
AND - Logical AND (lower precedence priority)
AND is not the same as &&, and OR is not the same as ||. They are close, but its the precedence that changes.
$a = 1;
$b = 3;
echo $a == $b; // False
echo $a == '1'; // True
echo $a === '1'; // False
echo $a & $b; // Creates 1
echo $a | $b; // Creates 3
echo $a ^ $b; // Creates 2
echo ~$a; // Creates... -2 I believe
echo $a >> 2; // Creates 4
echo $b << 2; // Creates 0
echo $a == 1 AND $b == 3; // True
echo $a == 1 OR $a == 2 && $b == 3; // True
I didn't test anything, but I think I got the logical ones right. I never use the operator precedence to control the variable orders. I always wrap my control orders with brackets since it more accurately represents what the mathematical function would look like.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.