You are here: Re: [PHP] what are {} used for in php? « PHP « IT news, forums, messages
Re: [PHP] what are {} used for in php?

Posted by Jochem Maas on 04/06/05 12:53

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
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация