Functions, Part I - Show What You Want


#1

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.

I have not so that
http://screenshot.sh/ouxzvh6Klu2S5

The last thing to uppercase is simple
but how to make randomly winner from my array?


#2



<?php
// Create an array and push on the names
// of your closest family and friends
$myarray = array();
array_push($myarray, "Lucja");
array_push($myarray, "Andrzej");
array_push($myarray, "Anna");
array_push($myarray, "Robert");
// Sort the list
sort($myarray);

// Randomly select a winner!
$counter = count($myarray);
$rander = rand (0,$counter);
print ($myarray["$rander"]);


// Print the winner's name in ALL CAPS
?>
</p>

Now is good?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.