# I miss an Array somewhere BUT where

#1

Hi Guys and Girls
I miss an Array somewhere
hope some1 can give me a push in right direction
here is my code.

<?php
// Create an array and push on the names
// of your closest family and friends
\$myArray = array();
array_push(\$myArray, "Spain");
array_push(\$myArray, "UK");
array_push(\$myArray, "Holland");
array_push(\$myArray, "France");
array_push(\$myArray, "Denmark");
array_push(\$myArray, "Sweden");

``````    // get number from array
\$number = count(\$myArray);
//print \$number;
// Sort the list
sort(\$myArray);
\$sort = join(", ", \$myArray);
//print \$sort;
// Randomly select a winner!
\$randomnumber = rand(0,5);
\$sub = substr(\$sort, \$randomnumber, \$number);
echo \$sub;
// Print the winner's name in ALL CAPS
?>``````

#2

what do you mean you miss an array somewhere? can you clarify? what is the error you are getting

#3

There are some options we have which we can play with:

``````\$myArray = array('Spain', 'UK', 'Holland');
array_push(\$myArray, 'France', 'Denmark', 'Sweden');
\$myArray[] = "Norway";
\$myArray[] = "Belgium";``````

We can sort before we count:

``sort(\$myArray);``

We can pick a winner in one statement:

``\$winner = rand(0, count(\$myArray));``

at which point we have only to output the winner:

``print strtoupper(\$myArray[\$winner]);``

Usually the simplest solution is the preferable one. If we go too far afield we create a debugging problem for ourselves. Given the above suggestions, see if you can still get your solution to work. If not, then don't be afraid to abandon it. Pounding the same piece of steel repeatedly eventually only weakens it.

#5

Thx mate
For very usefull info