Re: how call a variable in a text

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

 



Ashley Sheridan wrote on 2009-10-21 22:43:

The {} only become really useful when you're trying to reference arrays
within a string:

$var = array('great', 'boring');

$text = "this is {$var[0]}.";

Without the curly braces, PHP wouldn't be able to figure out whether you
wanted the end string to be 'This is great.' or 'This is [0].' despite
the variable itself clearly being an array.

Ehh what? This has never been a problem for me:

$text = "this is $var[0].";

However this does give an error (or notice, don't recall, haven't seen the error in quite a while):

$text = "this is $var['0'].";

In that case the solution is the curly brackets:

$text = "this is {$var['0']}.";

--
Kind regards
Kim Emax - masterminds.dk

--
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