This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Sam
over 8 years

Why is this not working?

Hey everyone, I’m currently on Functions Part I in the php course and i’m stuck with this question.

Task: to create a variable containing my name (Done this) then use rand() function or substr() to generate a random letter of my name but it’s only printing a number.

Code:

`$name=”Sam”; rand($name= 0,2);

print $name;`

Answer 560292d9d3292f597f00047a

0 votes

Permalink

Hi Umbriel,

$name = 'Sam';
$callname = substr($name, 0, 1); //the 1 is the letters across it goes, try 2 and 3.
print $callname;

or

 print $name[rand(1, strlen($name)-1)]; //random letter
points
Submitted by George Hatzi
over 8 years