首页 > 代码库 > PHP 9: 表达式
PHP 9: 表达式
原文:PHP 9: 表达式
最后举个来自PHP网站上的例子好了:
本章介绍PHP的表达式。
PHP的表达式其实和其他语言没有什么区别。普通的赋值是表达式,函数也是表达式,通过函数赋值也是。三元条件运算符也是,即:
$first ? $second : $third
这个很多语言里都有,不再多说。最后举个来自PHP网站上的例子好了:
1 <?php
2 function double($i)
3 {
4 return $i*2;
5 }
6 $b = $a = 5; /* assign the value five into the variable $a and $b */
7 $c = $a++; /* post-increment, assign original value of $a
8 (5) to $c */
9 $e = $d = ++$b; /* pre-increment, assign the incremented value of
10 $b (6) to $d and $e */
11
12 /* at this point, both $d and $e are equal to 6 */
13
14 $f = double($d++); /* assign twice the value of $d before
15 the increment, 2*6 = 12 to $f */
16 $g = double(++$e); /* assign twice the value of $e after
17 the increment, 2*7 = 14 to $g */
18 $h = $g += 10; /* first, $g is incremented by 10 and ends with the
19 value of 24. the value of the assignment (24) is
20 then assigned into $h, and $h ends with the value
21 of 24 as well. */
22 ?>
2 function double($i)
3 {
4 return $i*2;
5 }
6 $b = $a = 5; /* assign the value five into the variable $a and $b */
7 $c = $a++; /* post-increment, assign original value of $a
8 (5) to $c */
9 $e = $d = ++$b; /* pre-increment, assign the incremented value of
10 $b (6) to $d and $e */
11
12 /* at this point, both $d and $e are equal to 6 */
13
14 $f = double($d++); /* assign twice the value of $d before
15 the increment, 2*6 = 12 to $f */
16 $g = double(++$e); /* assign twice the value of $e after
17 the increment, 2*7 = 14 to $g */
18 $h = $g += 10; /* first, $g is incremented by 10 and ends with the
19 value of 24. the value of the assignment (24) is
20 then assigned into $h, and $h ends with the value
21 of 24 as well. */
22 ?>
PHP 9: 表达式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。