This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

257 points
96eb64b5d9a802417ab9bba33073430f?s=140&d=retro
Submitted by
Jay
almost 2 years ago

Why wont my code return the random selection from the array list

<?php
// Create an array and push on the names
// of your closest family and friends
$thearray = array();
array
push($thearray, "person 1");
array
push($thearray, "person 2");
array
push($thearray, "person 3");
array
push($thearray, "person 4");
array
push($thearray, "person 5");
$the
array = array(1,2,3,4,5);
sort($thearray);
print join(",",$the
array);
count($thearray)-1;
// Randomly select a winner!
$winner = array
rand ($the_array, 5);
// Print the winner's name in ALL CAPS
$uppercase = strtoupper($winner);
print $uppercase;
?>


0 votes

permalink

Why the underline in the $thearray, code? $winner = arrayrand ($thearray, 5);

362 points
5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro
Submitted by
joweb1
almost 2 years ago

1 Comment

96eb64b5d9a802417ab9bba33073430f?s=140&d=retro Jay almost 2 years ago

Thank you. I'm not sure why I put that in. !!


0 votes

permalink

<?php
// Create an array and push on the names
// of your closest family and friends
$myArray = array();
arraypush($myArray,"srinivas");
array
push($myArray,"srikanth");
arraypush($myArray,"monica");
array
push($myArray,"aishwarya");
array_push($myArray,"akshay");
$num = count($myArray);
// Sort the list
sort($myArray);
// Randomly select a winner!
$count = count($myArray)-1;
$random = rand(0, $count);
$winner= $myArray[$random];

// Print the winner's name in ALL CAPS
print strtoupper($winner);
?>

This works!!

614 points
580515a3e423ac332061998f8d11f619?s=140&d=retro
Submitted by
AkshayMonish
over 1 year ago