实例练习:
$str = "zjx".('a' === 'a') ? 'yes' : 'no';
var_dump($str); //'yes' 连接运算符优先级高于三目运算符
$a = 0;
$b = 2;
$c = 3;
$a && $b = $c;
echo "a:$a".PHP_EOL;
echo "b:$b".PHP_EOL;
echo "c:$c".PHP_EOL;
a:0 b:2 c:3 //&&优先级高于赋值运算符,并且 && 运算从左向右
$a = 1;
$b = 2;
$c = 3;
$a && $b = $c;
echo "a:$a".PHP_EOL;
echo "b:$b".PHP_EOL;
echo "c:$c".PHP_EOL;
a:1 b:3 c:3
$a =1 ;
$b = $a + $a +$a=2;
//4=1+1+2
// 结果$b=4
$a =1 ;
$b = &$a;
$c = ++ $a + $a ++;
var_dump($a,$b,$c); // 3 3 4
网友评论