[Solved] What is the difference between double and single quotes in PHP?

  

3
Topic starter

I am newbie to PHP..

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

1 Answer
3

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

Great! Thank you! Very useful!

Share: