This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

707 points
1a00edf8bf14c812f9a74c199401030a?s=140&d=retro
Submitted by
dnicholsonb
over 2 years ago

My Method, can it be improved?

$myName = "NAME";
$nameLen = strlen($myName);
$ans = substr($myName, rand(0, $nameLen), 1);
print $ans

This is how I solved #5. How about you? Is there a more efficient way to do it?


0 votes

permalink

almost same here!!

$name="keshava";
$x=strlen($name) - 1; //for array count type(starts from 0)//
echo substr($name,rand(0,$x),1);

409 points
Aee9d6d3bfb6c153776f79c3ca751b9e?s=140&d=retro
Submitted by
keshavanti
over 2 years ago