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

Functions, Part I Forum

View Course » View Exercise

474 points
Submitted by
Aaron Gomez
over 3 years ago

Why doesn't my code print out the elements in my array, instead of "array?"

So I know it is unnecessary for the exercise but I wanted to see it work. Here is my code:

    // Create an array and push 5 elements on to it, then 
    // print the number of elements in your array to the screen
        $friends= array("tori", "Nessa");
        array_push($friends, "Mark");
        array_push($friends, "Ariel");
        array_push($friends, "Brayden");
        array_push($friends, "Luke");
        array_push($friends, "Aaron");

        echo $friends;

        echo count($friends);

when I entered echo $friends, I expected it to return everything in my array. But instead it returned the word array. Why? Iv'e tried everything I can think of. Again I know it isn't necessary but plz help.

0 votes


What if you try print_r($friends); ?

450 points
Submitted by
over 3 years ago

1 Comment

Picture Magayane over 3 years ago

print_r will print elements and their position. He just want to print names in the array.

0 votes


instead of echo $friends;

try: print join(",", $friends);

251 points
Submitted by
over 3 years ago