⊗ppPmBsNN 23 of 447 menu

Negative Numbers in PHP

Numbers can be negative. To do this, a minus sign must be placed in front of the number:

<?php $a = -1; echo $a; // will output -1 ?>

The minus sign can be applied to both numbers and variables:

<?php $a = 1; $b = -$a; // wrote to $b the contents of $a with the opposite sign echo $b; // will output -1 ?>

Or like this:

<?php $a = 1; echo -$a; // will output -1 ?>

Create a variable $a with the value -100. Display this value on the screen.

Create a variable $a, write any positive or negative number into it. Display this number with the opposite sign on the screen.

byenru