Jump to content

what is this php syntax?


skaterdav85

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...