Functions, Part I


#1

Hello everyone, I cannot get through this, can anybody help?

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

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

$the_array = array(5, 3, 7 ,1);
rsort($the_array);
print join(",", $the_array);
?>

The error message is
"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() !"


#2

Not sure this is the fix, however we should note that $the_array does not need to be re-defined. It exists in memory. <?php ... ?> does not have its own scope. Variables are shared in memory until the end of the session.

The SCT permits white space in the delimiter:

rsort($the_array);
print join(', ', $the_array);

#3

the "glue" only wants single quotes here so print join(', ',$the_array);


#4

still not working

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

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