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

Functions, Part I Forum

View Course » View Exercise

1566 points
8f0555484952dfe8e6e02e8a7c9cf486?s=140&d=retro
Submitted by
Jacynth Agraan
over 2 years ago

Why doesn't this work?

<?php
$name = "Jacynth";
print substr($name, rand(0, strlen($name) - 1), 1);
?>

I keeps saying "Your printed output from rand() should be an integer."


1 vote

permalink

if you're talking about exercise 5/8, it's because it's asking for you to print a random number, then print a random number from your name.

you're right, that code does work- you've just skipped step 1 of the exercise.

324 points
Picture
Submitted by
David Fudge
over 2 years ago


0 votes

permalink

<?php

$name = "RahulSiyanwal";
$length = strlen($name);

$rand= rand(0,13);
echo $rand;
$sub = substr("RahulSiyanwal",$rand,1);
echo $sub;

?>

Well, I did that but I still getting the same error.

163 points
Picture
Submitted by
राहुल स्यानवाल
over 2 years ago

1 Comment

8f0555484952dfe8e6e02e8a7c9cf486?s=140&d=retro Jacynth Agraan over 2 years ago

You have to
echo $rand
in the first block of PHP