RE: [PHP] how call a variable in a text
| From: | Andrea Giammarchi | Date: | Thu, 22 Oct 2009 09:19:51 +0000 |
| Subject: | RE: [PHP] how call a variable in a text | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299185@lists.php.net to get a copy of this message | ||
Curly brackets are usually highlighted as well so it is a good practice, generally speaking, to use
them for double quoted strings and maintainability increase automatically.
Regards
> From: esamrat@barc.gov.in
> To: php-general@lists.php.net
> Date: Thu, 22 Oct 2009 11:31:53 +0530
> Subject: RE: [PHP] how call a variable in a text
>
> This is always safe to use variables like this...
>
> $text = "This is " . $variable;
>
> Or
>
> $text = "This is " . $variable[0];
>
> Regards,
>
> Samrat Kar
> FRD, BARC
>
> Tel: 022-25597295
> Alternate Email: esamrat@yahoo.com
>
>
> -----Original Message-----
> From: Kim Madsen [mailto:php.net@emax.dk]
> Sent: Thursday, October 22, 2009 2:25 AM
> To: ash@ashleysheridan.co.uk
> Cc: David Murphy; php-general@lists.php.net
> Subject: Re: [PHP] how call a variable in a text
>
> 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
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.423 / Virus Database: 270.14.25/2450 - Release Date: 10/21/09
> 16:44:00
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009