How to understand this formula (DEBUG_MODE 2) = 2)

Source: Internet
Author: User




How to understand this formula (DEBUG_MODE & 2) = 2)

(DEBUG_MODE & 2) = 2) // if this sentence is to be set up, it must be (2 & 2) = 2). How can this statement be understood?
Define ('debug _ mode', false); // if it is 2, 1 is displayed.

If (DEBUG_MODE & 2) = 2)

{

$ Smarty = '1 ';

}

Else

{

$ Smarty = '0 ';

}

Echo $ smarty;

?>

Copy code []


D8888D reply content -------------------------------------------------------
"= &" What is this operator?
$ User = & init_users ();
D8888D reply content -------------------------------------------------------
Yes, but I do not know what to use in front of the function.
D8888D reply content -------------------------------------------------------
Bitwise operations and operations...
D8888D reply content -------------------------------------------------------
Let me explain it.

In fact, here 2 should be a fixed value, which is a constant that defines your mode. If you write it like this, it will be easy to understand.

Define ('mode _ a', 2 );

$ Now_mode = 2;



If ($ now_mode & MODE_A) = MODE_A ){

Echo "the current mode is MODE_A ";

}

?>


Some students copied the code and said, why don't you use = for direct judgment? In fact, there is also a meaning of the contained relationship.
For example, the value of 6 & 2 is 2, and the value of 6 & 3 is 2, and the value of 2! = 3
This method usually represents a range. Let's take a look at the relationship between the IP address and the subnet mask in the computer network.
D8888D reply content -------------------------------------------------------
Thanks. LS. Your answer is easy to understand.
D8888D reply content -------------------------------------------------------
Original Post published by lmhllr at [url = http://www.111cn.cn/bbs/redirect.php? Goto = findpost & pid = 335104 & ptid = 46748] link mark [img] http://www.111cn.cn/bbs/images/common/back.gif?/img=#/url]
Bitwise operations and operations...
Can you explain his role? I still don't understand the intention of this writing.
D8888D reply content -------------------------------------------------------
Original Post published by jayliu at [url = http://www.111cn.cn/bbs/redirect.php? Goto = findpost & pid = 335044 & ptid = 46748] link mark [img] http://www.111cn.cn/bbs/images/common/back.gif?/img=#/url]
Yes, but I do not know what to use in front of the function.
Added &
Function return value is reference

Php5 is referenced by default and cannot be used in disorder. In php5, if the function returns false directly, the function with & is suspended, and php cannot find the referenced address.
D8888D reply content -------------------------------------------------------
I have learned new things from LS. Thanks to [img] http://www.111cn.cn/bbs/images/smilies/default/policy.gif#/img].
D8888D reply content -------------------------------------------------------
It turns out like this.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.