View Single Post
Old 11-28-2012, 05:25 PM   PM User | #7
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,502
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
No, single quotes are not used if there are doubles in the string.

Single quotes are used if there is no VARIABLES in the string that need to be replaced. Double quotes are used when there ARE VARIABLES in the string that need to be replaced.

Simply put:
PHP Code:
$Name 'Adrian';

Print 
'Hello $Name'// Hello $Name

Print "Hello $Name"// Hello Adrian 
As for single quotes used in the key and double quotes used for the name-string, well thats just down to the author. Technically it will work (and you can use double quotes in the key too) but using double quotes where they are not needed wastes CPU resources. If you have a script that is 2-3000 lines long and you're using double quotes all the way through when you could just use single quotes, thats going to take more time for the script to run and finish.

For the double quotes in a key that I mentioned..
PHP Code:
$Variable 'Item';
$Array["$Variable"] = 'Apple'//Will work but not needed because..

$Array[$Variable] = 'Apple'// Better.. BUT what if we need a second word in there (or an underscore)?? ..

$Array["$Variable Type"] = 'Apple'// OR..

$Array["{$Variable}_Type"] = 'Apple'// OR..

$Array[$Variable .'_Type'] = 'Apple'
In reality there are many ways to handle strings and variables but its just a case of picking the one that is best for the situation. I ALWAYS use single quotes for anything that has no variables inside it.

As mentioned above, "Kevin" is not wrong but it will force PHP to examine the string to see if it needs to work its magic and replace any variables. As there is not a variable in there then single quotes would be better.
__________________
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 05:32 PM..
tangoforce is online now   Reply With Quote
Users who have thanked tangoforce for this post:
Thyrosis (11-29-2012)