skaterdav85 Posted September 3, 2010 Share Posted September 3, 2010 I recently encountered this PHP syntax that I am not aware of on a screening test for a PHP position. The script was: <?php$alpha = 'abcdefghijklmnopqrstuvwxyz';$letters = array(15, 7, 15);foreach($letters as $val) {/* What should be here */echo $alpha{$val};}?> Can someone explain to me this part: $alpha{$val} I have never seen the curly braces used before. Thankfully I had my local server running and I had time to try all the choices Link to comment Share on other sites More sharing options...
Tino03 Posted September 3, 2010 Share Posted September 3, 2010 I believe It works the same as square brackets.So // thisecho $alpha[$val];// and thisecho $alpha{$val}; are the same thing. Link to comment Share on other sites More sharing options...
Ingolme Posted September 3, 2010 Share Posted September 3, 2010 Indicated here:http://es.php.net/manual/en/language.types.string.php Note: Strings may also be accessed using braces, as in $str{42}, for the same purpose. However, this syntax is deprecated as of PHP 5.3.0. Use square brackets instead, such as $str[42]. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.