By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

what is difference $a=10,$a='10' and $a="10"

P: 12
what is the main difference between in php
$a=10;
$a='10';
$a="10";

but all output is given 10 then what is the difference between these values?
Jan 17 '12 #1
Share this Question
Share on Google+
3 Replies


100+
P: 144
You probably need a PHP guy for scripting specifics, but here's my take: 10 without quotes is a number value. "10" in dbl quotes is a string. '10' with single quotes is used within the context of other strings, I mean for example, a javascript function call within an element attribute would look like this: onmouseover="myfunction('mystringvalue as an argument');"
This is for proper interpretation because if you put a " around the argument it actually would close the previous quote, style="myfunction(" and that's the end of my style statement. Wouldn't look to pretty. Keep in mind that if your using 1 type of quote in a particular context, use it entirely, on everything else within the context (don't switch back and forth: f1("mystring") and then f2('otherstring'). Some codes will tolerate using either or, and some will only allow dbl ". In an SQL statement you would use a single quote surrounded by dbl quotes to create a literal quote (") within a string. For example:
(assignment) X = "howdy"
( statement) .... "table.fieldname = '" & X & "', " . This would then literally be interpreted as:
table.fieldname = "howdy", . Without the single quote in there, it would say, table.fieldname = howdy, and unless howdy was a variable containing a numeric value an error is imminent. If a var named howdy was assigned a value of 1, then table.fieldname = howdy would be interpreted as table.fieldname = 1. That would survive if fielname is a number datatype, and so forth. Sometime three dbls """ will be used for Response.write "<a id=""" & myid & """ etc." So the output is exactly <a id="ID1" etc.
All you have to do is remember this and the other 19 thousand rules and you'll be okay. The program will tell you when you're wrong, so don't be shy about running a few tests.
I know somebody else has explained this better, so follow up with your inquiry for what suits your intake best.
Have a nice day!
Jan 17 '12 #2

100+
P: 144
Correction:

Response.write "<a id="" & myid & "" etc." produces <a id="ID1" etc.
Jan 17 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
Response.write "<a id="" & myid & "" etc." produces <a id="ID1" etc.
you are aware that this is not PHP syntax?

to the difference between ' and ". strings with ' are not parsed for variables while strings in " are:
Expand|Select|Wrap|Line Numbers
  1. $test = 1;
  2. echo "this is a $test"; // this is a 1
  3. echo 'this is a $test'; // this is a $test
despite that strings from ' and " are identical.

note that for strings there is also the HEREDOC and NOWDOC syntax.
Jan 17 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.