This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

601 points
Picture
Submitted by
Pourya Arami
almost 3 years ago

Show What You Know! 8/8

hey ladies and gentleman, i cant seem to figure out how to print out 1 name, can somebody please help me with this. thank you so much

<html>
    <p>
    <?php
    // Create an array and push on the names
    // of your closest family and friends
    $friends= array ();
    array_push($friends, "bart");
    array_push($friends, "Dennis");
    array_push($friends, "Bardia");
    array_push($friends, "Azra");
    array_push($friends, "Barend");
    array_push($friends, "Claudia");


    // Sort the list
    sort($friends);

    // Randomly select a winner!
    $namewinner=join($friends);
    $winner=rand(0,count($namewinner) - 1);

    // Print the winner's name in ALL CAPS
    echo strtoupper($winner);
    ?>
    </p>
</html>

3 votes

permalink

<?php

$nomes=array();
array_push($nomes,"thales");
array_push($nomes,"joao");
array_push($nomes,"pedro");
array_push($nomes,"mateus");

$a = count($nomes) -1;
sort($nomes);

$b = rand(0,$a);
echo strtoupper ($nomes{$b});

?>
</p>

366 points
Eaa2f6ccaab5eadc0964d6e256ffdb01?s=140&d=retro
Submitted by
thaldon
almost 3 years ago


0 votes

permalink

Work like this

<?php
// Create an array and push on the names
// of your closest family and friends
$names = array();
arraypush ($names, "Alicido");
array
push ($names, "Anitrica");
arraypush ($names, "Beridio");
array
push ($names, "Delorio");
arraypush ($names, "Lenionico");
array
push ($names, "Torintio");
array_push ($names, "Worikradio");
// Sort the list
sort ($names);
// Randomly select a winner!
$win = $names [rand (0, count($names)-1)];
// Print the winner's name in ALL CAPS
print strtoupper($win);
?>

234 points
E2ff1e8cc82db6a051761a35b2652bf4?s=140&d=retro
Submitted by
Duxaran
almost 3 years ago


0 votes

permalink

I'm was having issues with this as well. However, I passed the lesson with this code::

<html>
    <p>
    <?php
    // Create an array and push on the names
    // of your closest family and friends
    $family = array();
    array_push($family,"linda");
    array_push($family,"barb");
    array_push($family,"lois");
    array_push($family,"ashley");
    array_push($family,"devin");
    array_push($family,"camille");
    // Sort the list
    sort($family);
    // Randomly select a winner!
    $win = $family [rand (0, count($family)-1)];
// Print the winner's name in ALL CAPS
print strtoupper($win);
    ?>
    </p>
</html>

589 points
Picture
Submitted by
Ziana Nicole Mitchell
over 2 years ago


0 votes

permalink

<?php
// Create an array and push on the names
// of your closest family and friends
$fav= array();
arraypush($fav, "fera");
array
push($fav, "hlo");
arraypush($fav, "tela");
array
push($fav, "delaa");

// Sort the list
 sort($fav);

// Randomly select a winner!
$count= count($fav)-1;
$winner=$fav[rand(0,$count)];

// Print the winner's name in ALL CAPS

echo strtoupper($winner);
?>
</p>

188 points
Picture
Submitted by
Fernandez N Sangma
about 2 years ago


-1 votes

permalink

<?php
// Create an array and push on the names
$names = array("jessica","ema","zeza","diana");
array_push($names, "Maroon 5");
// of your closest family and friends

// Sort the list
sort($names);
// Randomly select a winner!
$t  = count($names);

 // Randomly select a winner!
$namewinner=join($names);
$position =  rand(0,$t);
$winner = $names[$position];
echo strtoupper($winner);
?>
</p>

611 points
6bb8f3738d9534b84ea43338ef569a72?s=140&d=retro
Submitted by
Gustav00
almost 3 years ago

1 Comment

E04d0b69645f395762b669b9fb3cbf2e?s=140&d=retro yoel neuman almost 3 years ago

remember to add -1 like this $t = count($names)-1;


-2 votes

permalink

//See if this works

<?php
// Create an array and push on the names
// of your closest family and friends
$names = array("Erica", "Sandria", "Quamori", "Shaquielle");
// Sort the list
sort ($names);
print join(", " , $names);
?>

<?php
/////////
$names = array("Erica", "Sandria", "Quamori", "Shaquielle");
rsort ($names);
print join(", ", $names);
?>

112 points
54b578cfe39efe1723003610_267602510
Submitted by
smille20
over 2 years ago