Skip to main content

-= Subtract By Operator

Laurence MorganLess than 1 minuteOperators And TokensAssignment

-= Subtract By Operator

Subtracts a variable by the right hand value (expression)

Description

The Subtract By operator takes the value of the variable specified on the left side of the operator and subtracts it by the value on the right hand side. Then it assigns the result back to the variable specified on the left side.

It is ostensibly just shorthand for $i = $i - value.

This operator is only available in expressions.

Examples

» $i = 3
» $i -= 2
» $i
1

Detail

Strict Types

Unlike with the standard arithmetic operators (+, -, *, /), silent data casting isn't supported with arithmetic assignments like +=, -=, *= and /=. Not even when strict-types is disabled (read more)

You can work around this by using the slightly longer syntax: variable = value op value, for example:

» $i = "3"
» $i = $i + "2"
» $i
5

See Also


This document was generated from gen/expr/subtract-by-op_doc.yamlopen in new window.

Last update:
Contributors: Laurence Morgan