View Single Post
Old 11-28-2012, 12:34 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Almost forgot..

In my link I don't actually explain braces but basically what they do is to tell PHP to treat that variable independently to the rest of the string. This is useful if you're using an array in a string (especially multidimensional arrays) or a string which contains a character such as _ which would be seen as part of the variable if you didn't seperate them.

PHP Code:
//Example 1
$Array['chaser'] = 'dog';
$Array['neighbours']['pet'] = 'cat';//Multidimensional array

Print "The {$Array['chaser']} chased the {$Array['neighbours']['pet']}";// The dog chased the cat

//Example 2
$Array[1] = 'under';
$Array[2] = 'score';

Print 
"This is how you might demonstrate using an {$Array[1]}_{$Array[2]}";
//This is how you might demonstrate using an under_score 
As you can see, php will treat those in braces inside a string as if they are seperate. Had I not used braces in the second example either side of the _ then PHP wouldn't have worked its magic there.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.

Last edited by tangoforce; 11-28-2012 at 12:37 PM..
tangoforce is online now   Reply With Quote
Users who have thanked tangoforce for this post:
Thyrosis (11-29-2012)