Difference Between Single Quotes and Double Quotes in Tabular Form

Sno.Basic TermSingle QuotesDouble Quotes
1.Programming languagePhpPhp
2.DefinitionIn Php simplest way to specify a string is to
enclose it in single quotes (the character ‘).
PHP will interpret the following escape sequences for special characters
3.Syntaxecho ‘a simple string’;echo “a simple string”;
4.Variableecho ‘a simple string’.$variable.’number’;echo “a simple string $variable number”
5.Working / Output
<?php
echo 'this is a simple string';
// Outputs: this is a simple string

echo 'Ahir once said: "I\'ll be back"';
// Outputs: Ahir once said: "I'll be back"

echo 'You deleted C:\\*.*?';
// Outputs: You deleted C:\*.*?

echo 'You deleted C:\*.*?';
// Outputs: You deleted C:\*.*?

echo 'This will not expand: \n a newline';
// Outputs: This will not expand: \n a newline

echo 'Variables do not $expand $either';
// Outputs: Variables do not $expand $either

$a =  45;
$b =  78;
echo 'Variables in A = '.$a.' and B = '.$b;
// Outputs: Variables in A = 45 and B = 78

?>
<?php
$juice = 'Orange';
echo "I like $juice juice"; 
// Output: I like Orange juice

$juice = 'orange';
echo "I drank some juice made of {$juice}s";    
// $juice will be parsed
/*
Complex variables will also be parsed 
within curly brackets
*/
$juice = array('apple', 'orange', 'plum');
echo "I drank some juice made of {$juice[1]}s";   
// $juice[1] will be parsed
// Output: I drank some juice made of oranges 


 

(Visited 777 times, 2 visits today)
Share with Friends :
Written by:

Leave a Reply

Your email address will not be published. Required fields are marked *