Newbie to PHP

Question, I’m a very rusty on PHP, and I’m wondering if anyone can tell me how to create this in one php script,
When I did the variable were carrying over from the previous line, I want the $num variable to always stay at 10.

<?php $num = 10; echo '

1. ' . $num . '

'; $a = $num + 2; echo "

2. $a

"; $b = $num - 1; echo "

3. $b

"; $c = $num * 3; echo "

4. $c

"; $d = $num % 5; echo "

5. $d

"; ?> <?php echo '

6.' .$num += 2 . '

'; ?> <?php $num = 10; echo '

7. ' . $num -= 1 . '

'; ?> <?php $num = 10; echo '

8. ' . $num *= 3 . '

'; ?> <?php $num = 10; echo '

9. ' . $num %= 5 . '

'; ?>

the culprit is ‘$num += 2’

$num += 2 means increase $num by 2. or meaning add 2 to $num and assign back to $num.

Likewise $num -= 1 means reduce $num by 1.

so are the others.

Instead you should be doing
echo ($num + 2);
echo ($num - 2);


like that.

Sponsor our Newsletter | Privacy Policy | Terms of Service