Difference between and in php
Simple question: What is the difference between ' and " in php? When should I use either?
asked Sep 9, 2009 at 22:54
johnnietheblackjohnnietheblack 12.8k27 gold badges91 silver badges132 bronze badges 5 Basically, single-quoted strings are plain text with virtually no special case whereas double-quoted strings
have variable interpolation (e.g. You can learn more about strings in PHP's manual. answered Sep 9, 2009 at 22:57
There are 3 syntax used to declare strings, in PHP <= 5.2 :
With single quotes :
For instance :
Will output :
For instance :
Will output :
For instance :
Will get you :
answered Sep 9, 2009 at 22:57
Pascal MARTINPascal MARTIN 388k77 gold badges647 silver badges656 bronze badges Any variables inside a " quoted string will be parsed. Any variables in a ' quoted string will not be parsed, and will be shown literally as the variable name. For this reason, ' quoted strings are very slightly faster for PHP to process.
I'd say use ' quotes unless you want variables inside your strings. answered Sep 9, 2009 at 22:57
The difference is, strings between double quotes (") are parsed for variable and escape sequence substitution. Strings in single quotes (') aren't. So, using double quotes (") you can do:
which will produce
The same in single quotes returns the literal string. Also, the characters that need to be escaped. If you have a string like:
you would probably use single quotes, to avoid having to escape the quotes in the string and vice-versa. answered Sep 9, 2009 at 22:57
Brenton AlkerBrenton Alker 8,8273 gold badges34 silver badges37 bronze badges " interprets escape characters and variables. ' doesn't do either. answered Sep 9, 2009 at 22:56
igustinigustin 1,0928 silver badges8 bronze badges In one word: when you would like to all your special chars (like \n) and varables (like $number) be noticed and process. answered Sep 9, 2009 at 22:57
IProblemFactoryIProblemFactory 9,3018 gold badges48 silver badges65 bronze badges What is the difference between != and !== In PHP?Operator != returns true, if its two operands have different values. Operator !== returns true, if its two operands have different values or they are of different types.
What is the difference betweenConclusion. The two operators, => and -> may look similar but are totally different in their usage. => is referred to as double arrow operator. It is an assignment operator used in associative arrays to assign values to the key-value pairs when creating arrays.
What is difference between and in PHP?The difference is, strings between double quotes (") are parsed for variable and escape sequence substitution. Strings in single quotes (') aren't. The same in single quotes returns the literal string. you would probably use single quotes, to avoid having to escape the quotes in the string and vice-versa.
What is the difference between & and && in PHP?Introduction to the PHP AND operator
The && and and operators return the same result. The only difference between the && and and operators are their precedences. The and operator has higher precedence than the && operator.
|