oliverj777 Posted August 26, 2010 Share Posted August 26, 2010 Hello, What is the difference Between "" and '' And also = and == Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/ Share on other sites More sharing options...
Pikachu2000 Posted August 26, 2010 Share Posted August 26, 2010 Single quotes cause everything within them to be interpreted as literal strings. = is an assignment operator, used to assign a value, == is a comparison operator, used to compare values $pie = 'blueberry'; echo "I have a $pie pie"; // will return "I have a blueberry pie", whereas echo 'I have a $pie pie'; // will return "I have a $pie pie". if( $pie == 'blueberry') { echo 'The pie is blueberry'; } else { echo 'The pie is NOT blueberry'; } Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104001 Share on other sites More sharing options...
kickstart Posted August 26, 2010 Share Posted August 26, 2010 Hi In "" variables will be interpreted (so "Hello $User" would put be "Hello Fred" is $User was equal to Fred), which will not be done in ''. = is an assignment, == is used to check a variable (and === is used to check a variable ensuring type, such as when checking true and false). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104004 Share on other sites More sharing options...
oliverj777 Posted August 26, 2010 Author Share Posted August 26, 2010 So if I were to say something like this: if($field = ''){ echo "Please fill in the field; } Does that look correct? Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104005 Share on other sites More sharing options...
oliverj777 Posted August 26, 2010 Author Share Posted August 26, 2010 I missed off the " after the echo ... Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104007 Share on other sites More sharing options...
Alkimuz Posted August 26, 2010 Share Posted August 26, 2010 text between single quotes is just only plain (html-)text, text between dubblequotes have a littlebit more richness, for example, you can place variables within dubblequotes and they will work, as in singlequotes i will just appear as text. Also you can use some extra layout for the text like codes as "\n" wich will work as <br>. for myself, i like to work as much as possible with only singlequotes when just working with plain html codes and text, but that differs between people the difference between = and == is very easy, the first is giving a variable a surtain value, the second is testing if a given variable is allready containing a surtain value $variable = 'hello world'; $variable contains now the text: 'hello world' if ($variable == 'hello world') { echo 'the variable contains the text: hello world!' } this code is testing if the variable is containing the text 'hello world', if so, the text 'the variable contains the text: hello world!' is displaid Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104009 Share on other sites More sharing options...
Zane Posted August 26, 2010 Share Posted August 26, 2010 Double quotes have the ability to parse the variables inside them.. Single quotes do not, they will contain whatever you put in them. Nevertheless, whichever quotes you do decide to use, if you want to put one of the same quotes within the string, you will have to escape it with the backslash $str = "Sometime I like to put quotes around a \"$variable\""; The same goes for single quotes. Nevertheless, Pickachu said it best. Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104010 Share on other sites More sharing options...
Pikachu2000 Posted August 26, 2010 Share Posted August 26, 2010 So if I were to say something like this: if($field = ''){ echo "Please fill in the field; } Does that look correct? No. That will always evaluate to TRUE since you're assigning, not comparing values. if( $field == '') would be the correct way to compare values. Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104012 Share on other sites More sharing options...
salathe Posted August 26, 2010 Share Posted August 26, 2010 No. That will always evaluate to TRUE No. That will evaluate to FALSE. Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104019 Share on other sites More sharing options...
Pikachu2000 Posted August 26, 2010 Share Posted August 26, 2010 Yeah you're right. With an empty string, it will evaluate to FALSE. Pardon my brainfart Quote Link to comment https://forums.phpfreaks.com/topic/211799-difference-between-and/#findComment-1104070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.