[SOLVED] >> I can't figure out what's the problem! PLEASE HELP! <<


There is a problem with my code and I can't figure out what's wrong. It works, but when I click on "Save and Submit" I get an error, but the code works and does what it's supposed to. Could someone find the problem?

Here is my code:

    // Create an array and push on the names
    // of your closest family and friends
    $family = array("Theodoros","George","Chris");
    // Sort the list
    // Randomly select a winner!
    print strtoupper($family[rand ( 0, count($family)- 1)]);
    // Print the winner's name in ALL CAPS

Here are the instructions:

  • Create an array() with the names of your closest family and friends. The more names in your array, the more fun your game will be!

  • After you've created your list, sort it and randomly select a name from the list.

  • When you have your winning name, print it to the screen in caps so everyone knows how awesome the winner is.

  • Functions we'll use here: array(), array_push(), sort(), count(), rand(), and strtoupper(). Play around with some of the other functions you've learned as well.


What kind of error do you get?

Oops, try again.
Did you remember to use array_push() in your code?

Also, if I try to do something with array_push, PHP gives me errors.


then show me the code where you use array_push() function. What else do you get?


I figured out the problem.
I did this array_push("Chris",$family); instead of this array_push($family,"Chris");.
Now my code works.

Thank you so much for trying to help me!


Yes, first argument is the array in which you want to push a value. Glad you solved it :slightly_smiling: