时间:2022-04-22 09:55:45 | 栏目:PHP代码 | 点击:次
实践出真知~
测试代码
输入测试:
<?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);
输出结果:
PHP Notice: Undefined index: d in /home/fanyu/abc.php on line 11
PHP Notice: Undefined index: d in /home/fanyu/abc.php on line 14
array(0) {
}
int(0)
int(0)
int(0)
int(0)
int(1)
int(0)
int(0)
int(0)
int(0)
结论
总结