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

Functions, Part I Forum

View Course » View Exercise

559 points
95c6e6c26f3dcc6f9db3c6a5c52b4e61?s=140&d=retro
Submitted by
mathiasfoster
almost 3 years ago

Getting Error "Oops, try again. Did you remember to use array() in your code? "

My code (all of it):

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

Receiving error message: "Oops, try again. Did you remember to use array() in your code?"
Anyone got any ideas?


1 vote

permalink

No need to declare the array again.

I found out your problem. in the join function there is a space between the comma and last quote, don't put a space there, instead write it like this

print join(",", $the_array);

813 points
55c22f1bd3292f41100006c3_183917643
Submitted by
Mark
almost 3 years ago

2 Comments

95c6e6c26f3dcc6f9db3c6a5c52b4e61?s=140&d=retro mathiasfoster almost 3 years ago

It also didn't work when I took the space out.

5466760b52f863f746004658_545622193 Joel Schmidt about 2 years ago

That worked for me, @Mark. Thanks!


0 votes

permalink

You have to declare an array again before rsort(), because there are two blocks of <?php...?>

123 points
8e0875918b892cdc7e198a09294e9caa?s=140&d=retro
Submitted by
frans.rippen
almost 3 years ago