LoginSignup
0
0

More than 3 years have passed since last update.

php 前置演算と後置演算の違い

Last updated at Posted at 2019-08-28

近況報告

エンジニア転職成功しました。YouTubeでエンジニア転職したい方向けに情報発信しています。

前置演算と後置演算の違い

前置演算

test.php
$t = 0;
$s = ++$t;
print $s;

/*結果
$t 1;
$s 1;
*/
  • $s = ++$x ような形で、先に演算してから値を代入する
  • $sに代入される値は、演算後の値である
  • 前置演算は加算子以外にも、--$xのような減算子の書き方が可能
  • ++をインクリメント、--をデクリメントと呼ぶ

後置演算

test.php
$t = 0;
$s = $t++;
print $s;

/*結果
$t 1;
$s 0;
*/
  • $s = $x++のような形で、$sに代入してから演算する
  • $sに代入される値は、演算前の値である
  • 後置演算は加算子以外にも、$x--のような減算子の書き方が可能
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0