Difference Between Single Quotes and Double Quotes in Tabular Form
Sno. | Basic Term | Single Quotes | Double Quotes |
1. | Programming language | Php | Php |
2. | Definition | In 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. | Syntax | echo ‘a simple string’; | echo “a simple string”; |
4. | Variable | echo ‘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)
Written by: