PHP Show What You Know


#1

Any help explaining why this does not work would appreciated:



<?php
$names = array();
array_push($names, "John");
array_push($names, "Bob");
array_push($names, "Carey");
array_push($names, "Lisa");
$sorted = sort($names);
$count = count($sorted) - 1;
$randNum = rand(0,$count);
$upper = strtoupper($sorted[$randNum]);
print $upper;
?>



#5

You have alot of extra in there you don't really need.
try something like this:

just sort($names);

and $winner=$names[rand(0,(count($names)-1];

and just print strtoupper($winner);

the above cleans this up a bit:

$sorted = sort($names);
$count = count($sorted) - 1;
$randNum = rand(0,$count);
$upper = strtoupper($sorted[$randNum]);
print $upper;