On Dec 18, 9:50 am, Royan <romayan...@gmail.comwrote:
Difference between quotation and apostrophe in PHP
I wonder is there any difference between strings wrapped into
quotation marks or into apostrophes and if so is there any situation
when one is preferable to the other?
-R.
The difference is that you can use variables directly in double quoted
strings.
Try this, for example.
<?php
$rand = mt_rand (1, 1000000);
echo ('The random number value is $rand<br />');
echo ("The random number value is $rand<br />");
You can also use \n in a double quoted string to insert a newline, \t
to insert a tab, etc. You can't do this with single quoted strings.
This doesn't mean that single quoted strings are inferior. They don't
have the overhead associated with variable insertion so if you're
doing huge amounts of string manipulation then single quoted is
faster. Also, you don't have to escape the " character in single
quoted strings, and given that attributes in HTML and XML are meant to
be surrounded by " characters this can be a quite significant
advantage.