Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Difference with assignment (-=)

Deduct the amount on the right from the balance.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$value -= $operand

Deduct the amount on the right from the balance. Each subsequent charge reduces the updated balance.

With integer operands a result within the integer range stays an integer. Overflow can produce a float and lose precision.

Evaluation

  • $value = 16; $value -= 5; → 11
  • $value = 4; $value -= 9; → -5
  • $value = 3; $value -= 0; → 3

Examples

<?php
$value = 16;
$value -= 5;
echo json_encode($value), PHP_EOL;

$value = 4;
$value -= 9;
echo json_encode($value), PHP_EOL;

$value = 3;
$value -= 0;
echo json_encode($value), PHP_EOL;

Result

11
-5
3

Sources