settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: What is the difference between double and single quotes in PHP?

+2 votes
I am newbie to PHP..

Just want to ask: in PHP what is the difference between single ('example') and double quotes ("example")?
asked in PHP category by user samfred5830

1 Answer

+2 votes
 
Best answer

SINGLE QUOTES:

When you put something in single quotes - even variable - it will ALWAYS be STRING;

Example:

<?php

echo 'Enter your grade:';
$grade = 4;
$oldGrade = 5;
$finalGrade = ($grade + $oldGrade) / 2;
var_dump($finalGrade);

echo 'dasdsadadasd$finalGrade';

Output:

output single quotes php

DOUBLE QUOTES:

In double quotes it WON'T BE ALWAYS STRING! If you add variable - it will show the variable.

Example:

<?php

echo 'Enter your grade:';
$grade = 4;
$oldGrade = 5;
$finalGrade = ($grade + $oldGrade) / 2;
var_dump($finalGrade);

echo "dasdsadadasd$finalGrade";

Output:

output double quotes in php

answered by user sam
selected by user samfred5830
Great! Thank you!
...