for example
Code: Select all
$apple = 'ripe'Code: Select all
$apple = "ripe"Moderator: General Moderators
Code: Select all
$apple = 'ripe'Code: Select all
$apple = "ripe"Use single quotes, unless you need a variable parsed:method_man wrote:ive noticed in php that sometimes people use ' and sometimes people use ". when should you use which one?
Code: Select all
$apple = 'ripe';
$fruit = "The apple is $apple";Code: Select all
$apple = 'ripe';
$fruit = 'The apple is ' . $apple;Can you give a reason why? What's the downside of using double quotes all the time, unless you need to insert a variable literally but that can be escapedRoja wrote: Use single quotes, unless you need a variable parsed:
It avoids the variable being parsed, which can help protect you against unintentional miscoding.jshpro2 wrote:Can you give a reason why? What's the downside of using double quotes all the time, unless you need to insert a variable literally but that can be escaped
Code: Select all
echo "Lets echo a variable here: ".$variable.", and output a function here: ".date();IMHO ~ As long as you find a standard and stick to it. Single vs Double is quite trivial. However, with that said; here is my standardonion2k wrote:I use:It suits me.Code: Select all
echo "Lets echo a variable here: ".$variable.", and output a function here: ".date();
Code: Select all
echo 'Lets echo a variable here: '.$variable.', and output a function here: '.date();Code: Select all
echo '<a href="http://www.website.com">Click Me</a>';Code: Select all
echo "Name: $name\n";Code: Select all
echo "Name: $name\n";Code: Select all
echo "Name: " . $name . "\n"; //or echo "Name: ", $name, "\n";Code: Select all
$string = 'But it's annoying when you're writing a sentence.';