Show what you know! - Question



I'm receiving an integer value, instead of a name. how do i fix this?

$family = array();
        array_push($family, "joe");
        array_push($family, "bill");
        array_push($family, "carl");
    $sorted = sort($family);
    $select = rand(0, count($sorted) - 1);
    echo $select;


rand() return an integer value, if you want to return the name of a person in the $sorted tab you have to use $sorted[position]


$rand = rand(0, count($sorted) -1);
$select = $sorted[$rand];


rand() expects exactly 2 parameters, 3 given (line 15)

How to deal with that?


I'm so confused plz help


you've got an extra comma in there somewhere.
the rand function returns a number.
The number is between the values x & y when rand is written like this: rand(x,y)
Array items are numbered from 0 onwards.
So, for this exercise you want a number between 0 and the count of the items in the array minus 1.


For people who are still trying to figure it out.
$family = array();
array_push($family, "x");
array_push($family. "y"); etc...

$sorted = sort($family);
^^ This variable is unnecessary since it's going to be randomised.
But it's here for the exercise.

$randomSelect = rand(0, count($family) - 1);
print strtoupper($family[$rand]);