8. Show What You Know!


#1


https://www.codecademy.com/courses/web-beginner-en-7I7Xm/0/8?curriculum_id=5124ef4c78d510dd89003eb8#


<html>
    <p>
	<?php
	// Create an array and push on the names
    // of your closest family and friends
    $name = array ();
    array_push($name, "Dennise"); 
    array_push($name, "Mia"); 
    array_push($name, "Sam");
    array_push($name, "Rose");
    array_push($name, "Nancy");
    array_push($name, "Josh");
	array_push($name, "Daniel");
	array_push($name, "Joseline");
	array_push($name, "Michelle");
	array_push($name, "Ruby");
	array_push($name, "Mike");
	array_push($name, "James");
	array_push($name, "Nori");
    
    // Sort the list
    sort($name);
    
	// Randomly select a winner!
	$winner = $name [rand(0,count($name)-1)];
    echo strtoupper($winner) ;
    
	// Print the winner's name in ALL CAPS

	?>
	</p>
</html>

The above codes are those I have tried to type my own, following the logic i know, and it works.
However, i would like to know is there any other "lighter " way to shorten my code, in order to show the same effect? In short, i would like to know a more efficient way to code this.
Thank you.


#2

You can push multiple values to array at once:

array_push($name, "Dennise", "Mia", "Sam", "Rose", "Nancy", "Josh", "Daniel", "Joseline", "Michelle", "Ruby", "Mike", "James", "Nori");

#3

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