• Register

Php provides different methods to handle strings. Strings can be defined using both single and double quotes in PHP. To use a variable in the single quote you need to concatenate the variable, while in a double-quoted string you can easily use a variable inside the string.
Single Quotes
When we use a single (‘ ’) quote PHP will output the whole string as it is, mean in the same way as you want. Even if you put variables in a single-quoted string it will ignore it print as it is. Moreover, special characters have no special effects in the single-quoted string. The single quote is a little faster than the double quote method. You cannot use escape sequences directly in single-quoted strings, The only way is that you can use a backslash is to display literal single-quote. While to display backlash you need a double backslash.
Syntax of the single quote:


echo 'this is single-quoted string example';
// to use variable you need to catcatenate 
$var= 123;
echo' value of variable is'.$var;
//to use single literal you need /
echo 'it/'ll be fine tomorrow';


Double Quotes:
Double quotes interpret the string one by one so you can use the variable inside the double quote. It will interpret or evaluate the variable to show the output. The variable must be declared with $ sign or within {} brackets.  A double quote has the ability to evaluate escape sequences and variables.
Syntax of the double quote:

// example of double qouted string
echo " hi, welcome to my site";
// variable inside double quoted string 
echo "the given number is $number";

conclusion: both single and double-quoted strings are very important in terms of the situation or condition. single-quoted is best for stirring only but if you need variables to be displayed you need a concatenation operator. while in the double quote you can easily implement variables.

4,670 points
9 5 1