What does `$page -= 1` in my PHP document mean? [duplicate]
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:
$x += 1;
($x = $x + 1
)$x -= 1;
($x = $x - 1
)$x *= 1;
($x = $x * 1
)$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.
精彩评论