How to understand this judgment expression ((DEBUG_MODE 2) == 2)_PHP tutorial

WBOY
Release: 2016-07-13 10:51:40
Original
1203 people have browsed it




How to understand this judgment expression ((DEBUG_MODE & 2) == 2)

((DEBUG_MODE & 2) == 2)//If this sentence is to be true, it must be ((2 & 2)==2). How do you understand this formula?
define('DEBUG_MODE',false);//If yes 2, execution will display 1

if ((DEBUG_MODE & 2) == 2)

{

$smarty = '1';

}

else

{

$smarty= '0';

}

echo $smarty;

?>

Copy code [ ]


D8888D reply content------------------------------------------------- ----------
"=&" What kind of operator is this?
$user =& init_users();
D8888D reply content------------------------------------------------- ----------
It’s a reference, but I don’t know what the use of adding & in front of the function is.
D8888D reply content------------------------------------------------- ----------
The AND operation in bit operations...
D8888D reply content------------------------------------------------- ----------
Let me explain

In fact, the 2 here should be a fixed value, a constant that defines your mode. It will be easier to understand if you write it like this

define('MODE_A',2);

$now_mode = 2;



if(($now_mode & MODE_A) == MODE_A){

echo "The current mode is MODE_A";

}

?>


Copy the code. Some students said, why not use == to judge directly? In fact, there is another meaning here, which is the included relationship
For example, the value of 6 & 2 is 2, and the value of 6&3 is also 2, and 2 != 3
This method can often represent a range. Compare the relationship between IP and subnet mask in computer networks to understand
D8888D reply content------------------------------------------------- ----------
Thank you LS, your answer is easy to understand.
D8888D reply content------------------------------------------------- ----------
Original post posted by lmhllr on 2007-12-17 17:27 [url=http://www.111cn.cn/bbs/redirect.php?goto=findpost&pid=335104&ptid=46748]Link tag[img]http:// www.111cn.cn/bbs/images/common/back.gif[/img][/url]
The AND operation in bit operations...
Can you explain its function? I still don’t understand the purpose of writing this way.
D8888D reply content------------------------------------------------- ----------
Original post by jayliu on 2007-12-17 16:55 [url=http://www.111cn.cn/bbs/redirect.php?goto=findpost&pid=335044&ptid=46748]Link tag[img]http:// www.111cn.cn/bbs/images/common/back.gif[/img][/url]
It’s a reference, but I don’t know what the use of adding & in front of the function is.
Added&
The function return value is a reference

PHP5 defaults to reference, and you cannot use & randomly. In PHP5, if the function directly returns false, the function with & will hang, and PHP will not be able to find the reference address
D8888D reply content------------------------------------------------- ----------
I learned something new from LS. Thank you[img]http://www.111cn.cn/bbs/images/smilies/default/victory.gif[/img]
D8888D reply content------------------------------------------------- ----------
So that’s it

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632550.htmlTechArticleHow to understand this judgment expression ((DEBUG_MODE 2) == 2)//If this sentence is to be true, it must be ((2 //If 2 is yes, execution displays 1 if ((DEBUG_MODE } else { $smarty= '0'; } echo $smarty; ?> Copy...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template