In the last line of the following code, it has &2, if($page['special']&2).

What does & mean?

Thanks in advance.

else $id=0;
if($id){ // check that page exists
    $page=dbRow("SELECT * FROM pages WHERE id=$id");

// { if page is hidden from navigation, show a message saying that
if($page['special']&2)echo '<em>NOTE: this page is currently hidden from the front-end navigation. Use the "Advanced Options" to un-hide it.</em>';


possible duplicate of Reference - What does this symbol mean in PHP?

Written by Gordon

In the context of this question & was part of binary math, not a 'by reference' operator

Written by Dmitri

@Dmitri that case is covered in the linked reference as well.

Written by Gordon

Accepted Answer

$page['special'] & 2


$page['special'] bitwise AND 2

It basically checks to see if the 2 bit is set in $page['special'].

This line:


explicitly adds 2 to $special so that it'll satisfy the bitwise AND operation and comparison, because decimal 2 == binary 10, with the 1 representing the 21 bit, ensuring it is set.

The AND operation returns 2 if the 2 bit is set, which resolves to true in PHP and satisfies the condition; otherwise it returns 0 which is considered false.

Quite a neat trick IMO, not sure how secure it is though.

Written by BoltClock
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the community.
It is licensed under cc-wiki