Am stucked in the last exercise of "Function part 1"


#1

I can't really get my rand function to print the winner correctly from my array. Can someone really help?


#2

@ifunanya1989,
As an Array can only be accessed using an INTEGER
you will have to round() your random() outcome....
and on top of that you will have to use the strtoupper() Method.....


#3

See you have to get the rand number by using the rand() and you have to access the rand winner by just calling out the array().Nothing big deal,it's quite cool if you look into this deeply.Hope my below code give you a right perception.


<?php
// Create an array and push on the names
// of your closest family and friends
$myName=array();
array_push($myName,"Soundharya");
array_push($myName,"Cinda");
array_push($myName,"Emi");
// Sort the list
sort($myName);
// Randomly select a winner!
$a=count($myName);
$b=rand(0,$a-1);
$c=$myName[$b];
// Print the winner's name in ALL CAPS
print strtoupper($c);
?>


#4

After running your code also i am getting an error message as Remember to print out the name of the lucky winner!
help!!!


#5

Thanks a lot!

I realised I did't have to make another variable here:


#6

So do I!:joy:joy:joy:joy: