Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Basics Unit Converter Manipulating Numbers

I cannot figure out how to add and subtract numbers in php.

my code is the following:

<?php

//Place your code below this comment $integerOne = 1; $integerTwo = 2; ?>

the code challenge is "Add 5 to $integerOne and subtract 1 from $integerTwo."

index.php
<?php

//Place your code below this comment
$integerOne = 1;
$integerTwo = 2;
?>

2 Answers

Daniel Pérez
Daniel Pérez
13,402 Points

Try this:

$integerOne = 1; $integerTwo = 2;

$integerOne += 5; $integerTwo -= 1;

The "+=" operator takes the value of the variable $integerOne and adds 5. It's equal to $intergerOne = $integerOne + 5;

Ricky Johnston
Ricky Johnston
27,445 Points

Hey Madison!

The PHP docs for arithmetic operators are here: http://php.net/manual/en/language.operators.arithmetic.php

TL;DR version:

For example, to add 5 to $integerOne and store the result in the same variable --

$integerOne = $integerOne + 5;

or, for shorter code

$integerOne += 5;

I know this kind of thing can feel tricky when you start. Good luck!