Help me this code!


Who can help me?
Why this code is flase!

// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$name = "Nguyen Trung Duc";
echo substr($name,rand(0,strlen($name)-1),1);


I passed the lesson with your code, as such,

    $name = "Nguyen Trung Duc";
    echo substr($name,rand(0,strlen($name)-1),1);

Not sure how to explain why yours does not.


I have fixed it so Thank you so much!


Yeah, i passed with your code, but i had to space it all out first. I also used print instead of echo (not that it would change much).

$name = "Nguyen Trung Duc";
print substr($name, rand(0, strlen($name) - 1), 1);

I don't understand why it didn't work, maybe it was because of the spacing (i doubt it). it wouldn't of been the echo part because @mtf used echo.

The code you have given us was correct.
therefore the only problem i could think of is if you had:
-> Typed it in the wrong place.
-> There was an error in another section of your code.

Hope this helped.


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