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 ;}