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 Arithmetic Operators

I don't get seven when I type $a++;

treehouse:~/workspace$ php numbers.php
PHP Parse error: syntax error, unexpected ';' in /home/treehouse/workspace/numbers.php on line 24

Parse error: syntax error, unexpected ';' in /home/treehouse/workspace/numbers.php on line 24
treehouse:~/workspace$

My code was:

<?php
$num_one = 1;
$num_two = 2;
$num_three = 3;

/*var_dump( $num_one );
var_dump( 1 );
var_dump( '1' );
var_dump( $num_one + $num_two - $num_three);*/

$distance_home = 1.2;
$distance_work = 2.5;
var_dump($distance_home + $distance_work + $num_three + .3);

$a = 5;
$b = 10;

var_dump($a * $b);
var_dump($a / $b);


$a = $a + 1;
var_dump($a);
$a++;
?>

5 Answers

put var_dump($a); after your a++ and you will get your seven

I got caught out by this as well. It would have helped if Alena Holligan had shown the duplicated line on screen below the increment line.

yes i think if she had shown how she duplicated it would be easier

Angyal István
Angyal István
11,288 Points

Try one of them:

$a++;

$a += 1;

++$a;

$a = $a + 1;

But the problem maybe is that, You write the last value giver "$a++" after the "var_dump($a)", so the var_dump still contains the upper value of the $a.

I hope I can You!

this got me too - should have scrolled down to show we insert $a++ in between

Ryan Dower
Ryan Dower
3,141 Points

I got caught out by this as well - thank goodness for this post.