php - The array is showing the count number not $name -
this through codecadamey tutorial , not explain or has no source correct code me find why posting here. have tried post in forums have not got conveniently speedy or correct answer here.
here code affiliated 'project' :
<html> <p> <?php // create array , push on names // of closest family , friends $names = array(); array_push($names, "brittany"); array_push($names, "nane"); array_push($names, "pops"); array_push($names, "timothy"); array_push($names, "patrick"); array_push($names, "cyndie"); array_push($names, "dad"); array_push($names, "mindy"); array_push($names, "gunner"); array_push($names, "nick"); array_push($names, "mark"); array_push($names, "scott"); array_push($names, "joe"); array_push($names, "dodi"); array_push($names, "cory"); array_push($names, "joey"); array_push($names, "taylor"); array_push($names, "tony"); array_push($names, "lynn"); array_push($names, "ella"); array_push($names, "zachary"); array_push($names, "corey"); count($names); // sort list sort($names); // randomly select winner! $winner = rand(0, 21); // print winner's name in caps print strtoupper($winner); ?> </p>
the outcome of code should display name within $names array (array_push) not. outcome of code displays number in between 1 , 22.
for example seeing in preview screen this:
9
all answers , responses appreciated!
best regards,
codi
you displaying random number.
try
print strtoupper($names[$winner]);
and want use $count
minus 1 upper bounds of rand()
:
// count list $count = count($names); // sort list sort($names); // randomly select winner! $winner = rand(0, $count - 1); // print winner's name in caps print strtoupper($names[$winner]);
Comments
Post a Comment