PHP Functions Part 1 8/8


#1

Really not having any luck with this code. Any advice would be so appreciated! Thank you

Hema :slight_smile:

<html>
    <p>
	<?php
	// Create an array and push on the names
    // of your closest family and friends
    $famnames = array ("Grandma","Mum", "Dad", "Alayna","Hema"){ 
array_push($famnames, "Grandma");
array_push($famnames, "Mum");
array_push($famnames, "Dad");
array_push($famnames, "Alayna");
array_push($famnames, "Hema");
}
print count ($famnames);
sort($famnames);
print join(", ", $famnames);
	// Sort the list
	// Randomly select a winner!
print $famname[rand(0, strlen($famname) - 1)]
	// Print the winner's name in ALL CAPS
$uppercase = strtoupper($famname);
   print $famname;
   	?>
	</p>
</html>


#2

Two things about the above,

  1. There is only a need to define an empty array.
  2. There should be no block syntax wrapping those five lines.

    $famnames = array();
    
    array_push($famnames, "Grandma");

and so on.

If this line is not asked for, it may be removed:

This line,

is not needed and may raise an SCT error (not a parse error).

Try,

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

    print strtoupper($winner);

Finally, remove this line,


#3

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