PHP 9: 運算式

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   sp   for   

原文: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 ?> 

PHP 9: 運算式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.