Real knowledge comes from practice
The test code
Input test:
The test code
Input test:
<?php $array = [ 'a' => 1, 'b' => 2, 'c' => [], ]; $a = $array['c'] ?? 0; $b = $array['c'] ?: 0; $c = $array['d'] ?? 0; $d = $array['d'] ?: 0; $e = $array['c'] ? 1 : 0; $f = isset($array['c']) ? 1 : 0; $g = $array['d'] ? 1 : 0; $h = isset($array['d']['e']) ? 1 : 0; $i = !empty($array['c']) ? 1 : 0; $j = !empty($array['d']) ? 1 : 0; var_dump($a); var_dump($b); var_dump($c); var_dump($d); var_dump($e); var_dump($f); var_dump($g); var_dump($h); var_dump($i); var_dump($j); 1234567891011121314151617181920212223242526272829
Output results:
PHP Notice: Undefined index: d in /home/fanyu/abc.php on line 11PHP Notice: Undefined index: d in /home/fanyu/abc.php on line 14array(0) {}int(0)int(0)int(0)int(0)int(1)int(0)int(0)int(0)int(0)1234567891011121314
conclusion
- $a ??0 equals isset($a)?$a: 0. $a ?: 0 equals $a?$a: 0. Empty: determines if a variable is empty (null, false, 00, 0, ‘0’, “, etc., all return true). Isset: determines if a variable isset (false, 00, 0, ‘0’, “etc., which also returns true).
Read More:
- Error report and solution of PHP module introduced by Apache
- Solution to error report of Jackson coordinate introduced by spring
- php mysqli_ connect_ Error () and mysqli_ connect_ The difference of errno() function
- A method of collecting JS dynamic content by PHP
- After upgrading php7, PHP program prompts an error: operator not supported for strings in causes and Solutions
- PHP message: PHP Fatal error: Uncaught PDOException: SQLSTATE[08004] [1040] Too many connections
- The echo introduced in react reports an error: xaxis “0” not found
- PHP link database error PHP_ network_ getaddresses: getaddrinfo failed: Name or service not known
- php open(/var/lib/php/session/sess_4ofxxx, O_RDWR) failed: Permission denied (13)
- JavaScript summary: the difference between typeof and instanceof, and Object.prototype.toString() method
- PHP – PHP Error[2]: Error while sending QUERY packet. PID=*
- An error is reported when the less file is introduced into main.js
- Difference between isempty method and isblank method in stringutils
- C#: Analysis of the difference between write() and writeline()
- The difference between LSTM and Gru
- The difference between classnotfoundexception and NoClassDefFoundError
- Difference between getelementsbyname and getelementbyid
- The tutorial and difference of glew, glfw, glad and freeglut
- The usage and difference of atoi() and stoi() functions in C + +
- Python json.dumps () json.dump The difference between ()