This code works for what I want, but I'm wondering if it's okay to do anything inside the curly braces of the if statement. Is there a better way to write this?
if(empty($data) || $data == "unanswered")) { //do nothing } else { //display data echo $data; }
Instead, you can do the negation:
if(!empty($data) && $data != 'unanswered') echo $data;
This is legal in PHP and most other languages, but you can use the Boolean DeMorgan Law to shorten the expression if:
if(!empty($data) && $data != "unanswered"){ echo $data; }
DeMorgan's law simply denies Boolean expression.
. . DeMorgan ( ). , .
. , . ! (). :
if( ! ( empty($data) || $data == "unanswered" ) ) { // do something }
, . .
- , . , , -, , .
, , .
Source: https://habr.com/ru/post/1650069/More articles:Can I set a different artist for each DAG Airflow? - airflowAWS "eb deploy" always zips all files - gitSearch for the most frequently used word in a string field in the entire collection - stringThe real-time workflow when creating records is performed before the record is transferred to the database - c #Нет модуля с именем 'django.core.context_processors', в views.py - pythonWEB API - authorization on the controller or action level (without authentication) - authenticationscala, Initializing abstract vals - scalaQuerying a value from a JSON field in Flask-SQLAlchemy with postgresql - jsonPlayer build error: IOException: Could not move file - androidUnity Error: Unable to convert classes to dex format - jarAll Articles