Questions about logical operators

Source: Internet
Author: User
Doubts about logical operators $ value = 12;
Echo ($ value) AND isset ($ value); // correct syntax
Isset ($ value) AND echo ($ value); // error syntax

What is the reason for this?


Reply to discussion (solution)

Echo is a syntax structure, not a function. it is wrong to put it in the expression.
Isset ($ value) AND print ($ value); // you can

Print is also a syntax structure.
Echo ($ value) AND isset ($ value); // correct syntax, no error reported
Isset ($ value) AND echo ($ value); // error syntax

The expression can only be a scalar or a function.
Print is also a syntax structure, but it returns a value. So it can be used as a function

Echo is also an expression.

$ Value = 12;
Echo ($ value) AND $ value = 15; // correct syntax
Echo $ value; // 15

Print has a return value by default, but in the above code. It is OK to put echo in front of and. The value of $ value has changed.

Isset ($ value) AND print ($ value); // replace print with exit. Exit does not return any value.

I read the manual. Echo is also an expression...

Echo is also an expression.

Http://php.net/manual/zh/function.echo.php

Echo is not a function (it is a language structure). Therefore, you do not have to use parentheses to specify parameters. single quotation marks and double quotation marks are acceptable. Echo (not constructed in other languages) does not act like a function, so it cannot always use the context of a function. In addition, if you want to pass multiple parameters to echo, parentheses are not allowed.



Although exit is also a language structure, I guess it can behave like a function, so exit can be used.

Echo ($ value) AND $ value = 15;
Why can I put echo in front of it? Because this statement executes and first, and then returns the result of this logical and

Isset ($ value) AND echo ($ value );
This sentence is equivalent to if (isset ($ value) echo ($ value );
Therefore, isset ($ value) AND echo ($ value); here is a context expression, AND echo cannot be used.

Thank you! Understand.


I read the manual. Echo is also an expression...


Echo is also an expression.

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.