Re: what are {} used for in php?
| From: | Jochem Maas | Date: | Wed, 06 Apr 2005 09:53:52 +0000 |
| Subject: | Re: what are {} used for in php? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-212393@lists.php.net to get a copy of this message | ||
Jacques wrote:
I have often seen php code included inside braces. What does this mean or do?you mean inside a double quoted string? like: <?php $var = "{$myArray[$myAssocKey]} {$myObj->property}"; ?> the braces are used to delimit the variables that are to be interpolated, this is done to make sure that PHP doesn't get confused about which part of the string is a 'var' that needs to be replaced. searching on php + 'string interpolation' should give you more info on the matter. ... also braces can be used for direct access to chars in a string e.g: <?php $myString = "my String"; echo $myString{3}; // gimme a "S" ?> ...and if you mean braces like the following, then you need to go to the manual and read up on 'control structures': <?php if ($x) { echo '$x casts to boolean true!'; } ?>
Jacques