PHP 9: 表达式

本章介绍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  ?>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值