How to simplify php code that checks for null and sets value to replace null? -


i have write lot of code this:

         if ( !empty($value['fax'])) {                 $temp['fax'] = $value['fax'];          } else {             $temp['fax'] = "unknown";          } 

just wondering if there's shorter version of ...

use ternary operators:

$temp['fax'] = !empty($value['fax']) ? $value['fax'] : 'unknown' 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -