Unary expressions

1 minute to read Download PDF Edit

A unary minus operator is used to convert a number from negative to positive or vice versa. Note: there is no unary plus.

-8

represents the negative value of ‘8’. When used with a variable that already has a negative value (let’s assume $myVariable has the integer value “-7”) the result is positive:

-$myVariable

returns:

7