8. Show What You Know - PHP/Gaming Question


#1

Hey folks, I thought I would share my working solution to my problem: I can't decide which game I should buy first when it becomes immediately available (actually, I'll probably buy the one's I want anyways, but no matter!) I don't think you can simplify any more than what I have, but as always, I'm open to critique and ideas.

Here's a question: Can anyone tell me how to print a sentence for selecting the winner like "And the winner is, drumroll, $winner!!") All the things I've tried don't let me pass the editor or the course. Thanks in advance!

<html>
    <p>
    <?php
    // Create an array and push on the names
    // of your closest family and friends
    $games = array();
    array_push($games, "Wildlands");
    array_push($games, "Stellaris");
    array_push($games, "Star Citizen");
    array_push($games, "Kingdom Come: Deliverance");
    array_push($games, "Halo Wars 2");
    array_push($games, "The Division");
    array_push($games, "Far Cry: Primal");
    array_push($games, "Mass Effect: Andromeda");
    array_push($games, "Battlefront");
    array_push($games, "Dishonored 2");
    $sorted = sort($games);
    $random = rand(0, count($games)-1);
    $namewinner = join($games);
    $winner = $games[rand(0,10)];
    print strtoupper($winner);
    ?>
    </p>
</html>

In case anyone was wondering, the game PHP chose was Star Citizen - so I guess I'll be doing some waiting before I get to play what PHP wants to!


#2

String formatting is one way:

print  "And the winner is, drumroll, %s!" % ($winner)

#3

Thanks Roy - Further along into PHP and came across this, thank you.