This forum is now read-only. Please use our new forums! Go to forums
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
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
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency