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 trialWeston Morin
5,507 Pointsarray_reverse() Function quiz
In this quiz is asks what would be the output of the array after using
What would you expect the var_dump from the following code to be? $array = array("Hello", "World"); array_reverse($array); var_dump($array);
A array(2) { [0]=> string(5) "World" [1]=> string(5) "Hello" } B array(2) { [0]=> string(5) "Hello" [1]=> string(5) "World" }
It says the answer is (B). Is it an error in the quiz, or something else?
4 Answers
Stone Preston
42,016 Pointsthats because array reverse returns a new array that is the reverse of the array passed in as an argument. It doesnt modify the array argument, just returns a new one. So in this case your $array variable is still the same as it was at first, even after you used the reverse function
Weston Morin
5,507 PointsI see! Thank you! That was crafty ;)
Stone Preston
42,016 Pointsand you were right that if you did something like
$array = array_reverse($array);
that b would then be the answer, since you assigned your array variable the return value of the array_reverse function.
Weston Morin
5,507 PointsOkay, now I have one more question. I have tried to use the markdown for code and other things of the sort, but it never gets applied in my forum posts. Do you have any idea why? example
php $array = array_reverse($array);
Weston Morin
5,507 PointsI used three back ticks before and after that line of code. The php came after the first set as it suggests specifying the code in the cheat sheet.
Stone Preston
42,016 Pointsok that is single line markdown. to markdown a block of code (multiple lines) , skip a line so that there is an empty line between the text/top of the comment box. then add your 3 back ticks ( ` ) then go to a new line and add your code block, then go to a new line and add 3 more back ticks to close the block
here is a code block
that is multiple lines long
here is a single line snippet
Weston Morin
5,507 PointsThanks! I have wondered about that!
Weston Morin
5,507 PointsOkay, let me test that.
test block of code
Stone Preston
42,016 Pointsyou got it!
Weston Morin
5,507 PointsWeston Morin
5,507 PointsNever mind, I see now that they never apply the value of the revers to $array.