# Funtion 1 8/8 not working but it's doing what's needed?

I'm using this code:

<?php
\$friends = array();
arraypush(\$friends, "Garrett");
array
push(\$friends, "Mom");

\$count = count(\$friends);

\$sort = sort(\$friends) -1;

\$rand = rand(\$sort, \$count);

\$winner = \$friends [\$rand];

\$thewinner = strtoupper("\$winner");

print \$thewinner;
?>

It's printing out a random name but keeps giving me the error "Oops, try again. Remember to print out the name of the lucky winner!".... anything I'm doing wrong here?

1 vote

For future searchers... this solution did work:

<?php
// Create an array and push on the names
// of your closest family and friends
\$friends = array ();
arraypush(\$friends, "Ezra");
array
push(\$friends, "Diana");
arraypush(\$friends, "Bartok");
array
push(\$friends, "Mully");
arraypush(\$friends, "Tommy");
array
push(\$friends, "Erika");

// Sort the list
sort(\$friends);

// Randomly select a winner!
\$random = rand(0,count(\$friends) -1);
\$namewinner=join(\$friends);
\$winner = \$friends[rand(0,5)];
// Print the winner's name in ALL CAPS
print strtoupper(\$winner)
?>

Why did you write \$ particular winner = join (\$ friends);
I think it's not necessary

<?php
// Create an array and push on the names
// of your closest family and friends
\$names = array('Lisa');
arraypush(\$names, 'Lyn');
array
push(\$names, 'Gemma');
arraypush(\$names, 'Alex');
array
push(\$names, 'Jamie');
arraypush(\$names, 'Michelle');
array
push(\$names, 'Zoe', 'Alison', 'Anna', 'Ellie');

``````// Sort the list
sort(\$names);
\$count = count(\$names);
// Randomly select a winner!
\$winner = rand(0, \$count);
// Print the winner's name in ALL CAPS
print strtoupper(\$names[\$winner]);
?>
</p>
``````