This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

935 points
Fa9c7af470d97c2b9517815ee6568b85?s=140&d=retro
Submitted by
TypeCoder
over 2 years ago

7/8 Question - Why does this not work?

Error:- Oops, try again. Your reverse sorted array should have at least 3 elements in it. Make sure to pass a comma as the first argument to join() !
<?php
// Create an array with several elements in it,
// then sort it and print the joined elements to the screen
$the_array = array (9, 6, 2, 7, 5);
sort($the
array);
print join(",", $thearray);
// Reverse sort your array and print the joined elements to
//the screen

rsort($the
array);
print join(",", $the_array);
?>


0 votes

permalink

Your array is called "$the_array" - but when you sorted it you called it "$thearray".

510 points
Picture
Submitted by
Lurial
over 2 years ago

3 Comments

Fa9c7af470d97c2b9517815ee6568b85?s=140&d=retro TypeCoder over 2 years ago

I used '$thearray' in all contexts, but this editor removes underscores so what is posted is not what was typed. Using "$thearray" still gives same error.

Fa9c7af470d97c2b9517815ee6568b85?s=140&d=retro TypeCoder over 2 years ago

This was my actual code - still doesn't work:
<?php
// Create an array with several elements in it,
// then sort it and print the joined elements to the screen
$thearray = array (9, 6, 2, 7, 5);
sort($the
array);
print join(",", $the_array);
// Reverse sort your array and print the joined elements to
//the screen

rsort($thearray);
print join(",", $the
array);
?>

Fa9c7af470d97c2b9517815ee6568b85?s=140&d=retro TypeCoder over 2 years ago

Okay, here's my code line by line that worked. I reset the code, then typed in exactly below. Strange I did it step by step and got the rsort out of the way first, then did the sort etc. and that seemed to help.

  1. <?php
  2. // Create an array with several elements in it,
  3. // then sort it and print the joined elements to the screen
  4. $the_array = array (8,9,3,5,1,2,5);
  5. sort($thearray); print join(",",$thearray);
  6. ?>
  7. <?php
  8. // Reverse sort your array and print the joined elements to the screen
  9. rsort($thearray); print join(",",$thearray);
  10. ?>