Some questions about the PHP operator

Source: Internet
Author: User
Tags php operator
What I saw in the manual about the PHP operator

& $ Y returns true if both $ x and $ y are true. | Or $ x | $ y returns true if at least one of $ x and $ y is true.


But why do I often look at a lot of PHP files, including well-known open-source programs, all of which are reversed ??

For example, the condition code for deleting a certain information is

Is it an administrator and a publisher? In the manual, this means that the conditions for deleting information are administrator and publisher.


Why is it wrong in the manual?


Reply to discussion (solution)

How do you know that you are not out of context?

There is no problem in the usage manual of logical operators.

As for your example, are you sure you mean it?

For example, you can see where you are, and paste the code to show it.

For example, you can see where you are, and paste the code to show it.



For example, a file in the famous open-source Forum discuz

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {exit('Access Denied');}


Obviously, it must be in discuz and on the admin management page.

If you don't believe it, you can go to discuz and check the relevant php files.

Php does not have the function of user-defined operators.

It should not be used in reverse steps ~

For example, I want to determine whether both forms are filled in.

if(empty($_POST['a']) || empty($_POST['b'])){


In this way, two forms are indispensable and cannot be published.
In the php Manual
if(empty($_POST['a']) && empty($_POST['b'])){

You only need to fill in one item to publish it.
Tested in person!

Sorry, the brackets are missing. you just need to understand this.

For example, I want to determine whether both forms are filled in.

if(empty($_POST['a']) || empty($_POST['b'])){


In this way, two forms are indispensable and cannot be published.
In the php Manual
if(empty($_POST['a']) && empty($_POST['b'])){

You only need to fill in one item to publish it.
Tested in person!



The code below is not fully written. how do we know whether it is reversed?
Besides, how are you sure the author's idea is not like this?

If (empty ($ _ POST ['A']) | empty ($ _ POST ['B'])
It is expressed as long as one of the $ _ POST ['A'] and $ _ POST ['B'] is null (of course, both of them are null ).

If (empty ($ _ POST ['A']) & empty ($ _ POST ['B'])
The expression is valid only when $ _ POST ['A'] and $ _ POST ['B'] are empty.

The two are obviously different, although both are empty expressions
You have to select a qualified expression based on your business needs.


For example, I want to determine whether both forms are filled in.

if(empty($_POST['a']) || empty($_POST['b'])){


In this way, two forms are indispensable and cannot be published.
In the php Manual
if(empty($_POST['a']) && empty($_POST['b'])){

You only need to fill in one item to publish it.
Tested in person!



The code below is not fully written. how do we know whether it is reversed?
Besides, how are you sure the author's idea is not like this?




I mean

If (empty ($ _ POST ['A']) | empty ($ _ POST ['B']) {echo "Sorry, the table is incomplete ";} else {echo "published successfully ";}

In discuz, this type of code is considered to be a form and B form must be filled in all before it can be published.

While
If (empty ($ _ POST ['A']) & empty ($ _ POST ['B']) {echo "Sorry, the table is incomplete ";} else {echo "published successfully ";}

It is assumed that at least one of them can be published.

I am also surprised to discuss it .......

Your own logic: You think c = a & B; and! A or! B = c equal?

If (! Defined ('in _ DISCUZ ') |! Defined ('in _ admincp ')){
Exit ('Access Denied ');
}


This means that if one of them is not satisfied, the scope of judgment should be wider. for example, the table is square-> The table is a square table,
Or, it can be seen that a table is not square or not satisfying a four-party table. I personally think it is more efficient or used to judge.

This indicates that a is empty or B is empty.
If (empty ($ _ POST ['A']) | empty ($ _ POST ['B']) {
Echo "Sorry, the form is incomplete ";
} Else {
Echo "published successfully ";
}

This indicates that both a and B are empty.
If (empty ($ _ POST ['A']) & empty ($ _ POST ['B']) {
Echo "Sorry, the form is incomplete ";
} Else {
Echo "published successfully ";
}

Logically, the two are different. I don't understand why the landlord thinks there is a problem. these are done as needed.

Related Article

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.