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

Ilona Bittencourt
Ilona Bittencourt
2,717 Points

Operators and var_dump General Questions

I don't understand why I'm getting a "float(7)" in return when I run the script "var_dump($a * $b);" being $a=5 and $b=10, just like in the video

And also, why is that in the minute 03:28 of the video she gets a return of "int(6)" when runing the script "var_dump($a--);" isn't supposed to be "int(5)" because the "$a--" substracts 1 from the last variable value (that was 6).

2 Answers

Hi Ilona,

The answer to your second question is because the decrementing operator $a-- substracts 1 after displaying the results of the var_dump($a--) operation. The value of $a is still 6 until the var_dump operation is complete. Once the operation is complete the value of $a will then be 5. Trying running the var_dump operation repeatedly a few times.

With $a having the value of 6 running the first time. var_dump($a--) will display 6 however when the operation is complete the value of $a is 5. Now running it a second time with the value of $a as 5 var_dump($a--) will display 5 however when the operation is complete the value of $a will be 4. Now running it the third time with the value of $a as 4 var_dump($a--) will display 4 however when the operation is complete the value of $a will be 3.

In all the cases above we are displaying the value of $a before the variable is actually decremented.

For your first question. I can review it tomorrow night if you would like to post the full code.

Ilona Bittencourt
Ilona Bittencourt
2,717 Points

Thanks a lot! I get it now :)

Daniel Stopka
Daniel Stopka
13,520 Points

Hi Ilona,

the results are from all var_dumps from the beginning of the video...

so float(7) is var_dump of that $distance_home + $distance_work + $num_three * 0.3 and it is every time showing, because the var_dump function was not removed, so it is showing the results every time the scripts runs...

Same for all other var_dumps, each line of result in console represents return of var_dump functions used in the code...

Hope this helps, if something, write a comment :)

Ilona Bittencourt
Ilona Bittencourt
2,717 Points

So, what do I have to do in order for the script to run and return the int(50) that she got when she ran the script in the video. Also, still don't get why in the minute 03:28 of the video she gets a return of int(6) when runing the script var_dump($a--); insted of int(5), because the $a-- substracts 1 from the last variable value (that was 6), than the return should've been int(5).