Re: what are {} used for in php?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux