Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJiaming Zhang
10,170 Pointsget subset of string in PHP
I am following the new PHP Basics - String & Booleans episode. In the tutorial, Hampton use a method to obtain a letter in a string, like
$name = "Jason";
echo $name{0};
It does not work for me. I am using "PHP 5.4.24 (cli)" on a Mac machine. Anyone has some idea what may goes wrong. Thanks.
3 Answers
Chris Malcolm
2,909 Pointstry [] not {}
<?php
echo $name[0];
?>
Oğulcan Girginc
24,848 PointsIf that's the case, how come { } works in Hampton Paulk's example? :/
Josh Grupp
7,060 PointsChris has this right, the square brackets "[" and "]" are what you use for specifying the position in the string.