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.