-1
votes

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 -=

Thanks!

4

4 Answers

3
votes

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)
7
votes

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

$page = $page - 1;
1
votes

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

1
votes

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