# Stuck in: 5/8 Math Function II

#1

Hi,

Thanks.

#2

@christinewong,
They want you to
`randomly` `print` 1 character from the `\$name` variable-string

``````string substr ( string \$string , int \$start [, int \$length ] )
^                ^            ^
^                ^            ^
\$name              ^            1
^
int rand ( int \$min , int \$max )
^           ^
^           ^
0       (strlen( \$name ) -1)``````

#3

you can refer to my code..i thing i work..hihi

<?php
// Use rand() to print a random number to the screen
echo rand(1,100);
?>

<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
\$name="phamdaoan";
\$num=rand(0,strlen(\$name));
echo \$name[\$num];
?>

#4

omg your are a genus you helped me thank you!!!!

#5

Hello!

You're pretty close! You don't need to print every function that you have learned from the lesson. This is the code I used:

``````\$name = "Jonathan";

//Determine the string length of your name
\$length = strlen(\$name);

//Determine a random number between 0 and the lenght of your name
\$rand = rand(0, \$length);

//Use substr to pick a random character. The three parameters passed for substr
//Are String(your name), Starting point(We want this to be random), and how many
//Characters we want listed(1)
\$randChar = substr(\$name, \$rand, 1);

echo \$randChar;``````

Hope this helps!! Don't give up and happy coding

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.