8/8 on Functions Part 1


#1

It keeps saying that the output should be an integer! Not sure what this means! :frowning:


<?php
// Create an array and push on the names
// of your closest family and friends
$friends = array ();
array_push($friends, "Mum");
array_push($friends, "Dad");
array_push($friends, "Alayna");
array_push($friends, "Bobby");
array_push($friends, "Rocky");
array_push($friends, "Hema");

// Sort the list
sort($friends);

// Randomly select a winner!
$random = rand(0,count($friends) -1);
$namewinner=join($friends);
$winner = $friends[rand(0,5)];
// Print the winner's name in ALL CAPS
print strtoupper($winner)
?>


#2

it is probably because your output is coming out as string and you should convert the output into integer


#3

refresh/reload your browser then try it. :slight_smile:


#4

no still no good. So how would I make the output into an integer?


#5

casting might do it...

$num = "3.14";
$int = (int)$num; //(int) does the casting
$float = (float)$num;

http://www.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting


#6

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