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

Functions, Part I Forum

View Course » View Exercise

166 points
Picture
Submitted by
Brad Bortnem
almost 3 years ago

Code works, but keeps giving me a "array should have 3 elements in it"

Code works fine. I just can't move forward because of "your reverse sorted array should have 3 elements in it." What am I missing??

<?php
// Create an array with several elements in it,
// then sort it and print the joined elements to the screen

$thearray= array(4, 11, 88, 2341, 999);
sort($thearray);
print join(",",$thearray);


// Reverse sort your array and print the joined elements to the screen

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

</p>

13 votes

permalink

i changed my previous code to this and it worked::

<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(4,9,7,3,1,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>

589 points
Picture
Submitted by
Ziana Nicole Mitchell
almost 3 years ago


0 votes

permalink

i'm having the same problem my code meets the lesson critiera but at the sae time i keep getting errors about my sort(); and rsort();

here is my code::

<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(4,9,7,3,1,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>

589 points
Picture
Submitted by
Ziana Nicole Mitchell
almost 3 years ago


0 votes

permalink

It wants a comma as the glue for rsort

591 points
78282460eae250ae71d2dee40870229f?s=140&d=retro
Submitted by
Areg Abrahamians
almost 3 years ago

1 Comment

Picture Gaynor almost 3 years ago

That's exactly it - spent such a long time on this as the syntax looked correct!!!


0 votes

permalink

Here's my code: It isn't working


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


<?php
// Reverse sort your array and print the joined elements to the screen
the screen
rsort($the
array);
print join(", ",$the_array);
?>

372 points
C46dd05bcc952b66c8b54cb7fe61f9a3?s=140&d=retro
Submitted by
Jasmine Gomez
over 2 years ago