Reputation: 4171
Can someone please explain in detail what these if statements are doing?
What does the three === signs to in the first one, and What does the single & in the second mean?
$aProfile = getProfileInfo($iId);
if($aProfile === false)
return false;
if(!((int)$aProfile['Role'] & $iRole))
return false;
Upvotes: 1
Views: 134
Reputation: 22350
===
tests for type-safe equality.
'3' == 3
will return true, but '3' === 3
will not, because one's a string and one's an integer. Similarly, null == 0
will return true, but null === 0
will not; 10.00 == 10
will return true, but 10.00 === 10
will not.
&
is the bitwise AND operator. It returns a bitmask in which a bit is set if both the corresponding bits are set from the original two bitmasks.
For example:
$x = 5;
$y = 17;
echo $x & $y;
causes 1 to be echoed. $x
is ...000101
, $y
is ...010001
. The only bit that is set in both of them is the rightmost one, so you get ...000001
, which is 1.
Upvotes: 8
Reputation: 13351
Here's a good guide to PHP operators:
http://www.tuxradar.com/practicalphp/3/12/3
See the section on bitwise operators for info on the &.
Upvotes: 3