开发者

What does `$page -= 1` in my PHP document mean? [duplicate]

This question already has answers here: Reference Guide: What does this symbol mean in PHP?开发者_运维问答 (PHP Syntax) (25 answers) Closed 1 year ago.

I have the following variable defined in a PHP document I am working with, and I'm unsure what it means.

The PHP

$page -= 1;

The part I am unsure of is the -=


It's a shorthand to save typing. It's effect is idential to

$page = $page - 1;


The -= operator is shorthand for subtracting a value from the variable:

$x -= 1;
$x = $x - 1;

Here's some of the other ones:

  1. $x += 1; ($x = $x + 1)
  2. $x -= 1; ($x = $x - 1)
  3. $x *= 1; ($x = $x * 1)
  4. $x /= 1; ($x = $x / 1)


The -= operator is a combination arithmetic and assignment operator. It subtracts 1 then reassigns it to $page.


It's the same as $page = $page - 1, $page-- or --$page, it's used to decrement the value of the variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜