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

Functions, Part I Forum

View Course » View Exercise

628 points
45d2c674342a02598be7f5cf69baa3f3?s=140&d=retro
Submitted by
Blooms2
about 2 years ago

7/8 not working, no idea why tbh

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

<?php
// Reverse sort your array and print the joined elements to the screen
$thearray = array(7,1,4,2,5,3,6);
rsort($thearray);
print join (",", $thearray);
?>


0 votes

permalink

remove that space in last print statement
it should be like print join(",",$thearray);
..hope it will work

741 points
53b09c8be682c699cc412d6c2830f676?s=140&d=retro
Submitted by
indugumber
about 2 years ago

1 Comment

45d2c674342a02598be7f5cf69baa3f3?s=140&d=retro Blooms2 about 2 years ago

it says "our reverse sorted array should have at least 3 elements in it. Make sure to pass a comma as the first argument to join() !"


0 votes

permalink

I too have this problem.

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

Result

Oops, try again. Your sorted array
should have at least 3 elements in it.
Make sure to pass a comma as the first
argument to join() !

Well, it does have at least 3 elements, and the first parameter to join is ",".

Grrr.

172 points
0910e8d098a1411f6f6167eca665a83a?s=140&d=retro
Submitted by
Simon Greener
almost 2 years ago


0 votes

permalink

Same problem for me and still haven't found out why :(

632 points
8b5876a07a761a18043f3060708584cf?s=140&d=retro
Submitted by
Enejdi Drini
almost 2 years ago


0 votes

permalink

You have to separate your code into two elements, like this:

<html>
    <div>
    //first "p" tag:
    <p>
        <?php
            $the_array = array("1","3","4","2");
            sort($the_array);
            echo "sorted array: " . join(",",$the_array);;
        ?>
    </p>

    //second "p" tag:
    <p>
        <?php
            rsort($the_array);
            echo "<br> reversed sorted array: " . join(",",$the_array);

        ?>  
    </p>
    </div>

</html>

977 points
54558674282ae39b77002e3c_511388865
Submitted by
Tzachi Halevy
almost 2 years ago