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

Functions, Part I Forum

View Course » View Exercise

500 points
Fa2d06886e482c85ac4ff2d9255a2b52?s=140&d=retro
Submitted by
Nneka Udeagbala
about 2 years ago

Substring letters

I typed my substring as:
$myname = "Nneka";
$partial = substr($myname, 1, 4);
print $partial;

and it printed "neka".

Why did it print the a?

If I type:
$myname = "Nneka";
$partial = substr($myname, 0, 4);
print $partial;

It would print "Nnek".


1 vote

permalink

You need to do

$partial = substr($myname, 0, 5);

903 points
564667619113cba6c7000053_587542336
Submitted by
VeganGod
about 2 years ago