Ask a question about PHP assignment judgment

Source: Internet
Author: User
Ask a question about PHP assignment judgment. I just got in touch with PHP. in a MYSQL class, I saw this sentence $ condition = $ condition? 'Where'. $ condition: NULL does not mean anything clearly. could you please explain it. I personally understand it as follows: if 'where'. $ condition is empty, I want to teach you how to assign values to PHP.
I just got in touch with PHP and saw this sentence in a MYSQL class.
$ Condition = $ condition? 'Where'. $ condition: NULL
I am not very clear. could you please explain it.
I personally understand it as: if 'where '. $ condition is null, 'Where' is set '. $ condition is assigned to $ condition. On the contrary, $ condition = $ condition is assigned. if you do not know whether it is correct or wrong, please kindly advise !!

------ Solution --------------------
Depend! Upstairs error!

If 'where'. $ condition is null, assign 'where'. $ condition to $ condition. otherwise, set $ condition = $ condition.

=>

If $ condition is not empty, assign 'where'. $ condition to $ condition. otherwise, set $ condition = NULL.
------ Solution --------------------
This is a combination of SQL statements.
For example, if the user does not set a matching condition
SELECT * FROM tablename;
If a condition is set, that is, $ condition is not empty
SELECT * FROM tablename WHERE $ condition;
------ Solution --------------------
$? $ B: $ c
The ternary operator of php.
If $ a is true, the expression value is $ B. If it is false, the expression value is $ c.
------ Solution --------------------
PHP code
$ Condition = $ condition? 'Where'. $ condition: NULL // equivalent to if ($ condition) {$ condition = 'where'. $ condition;} else {$ condition = NULL ;}

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.