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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arvind vohra
    New Member
    • Jan 2012
    • 12

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

    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?
  • C CSR
    New Member
    • Jan 2012
    • 144

    #2
    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="my function('mystr ingvalue as an argument');"
    This is for proper interpretation because if you put a " around the argument it actually would close the previous quote, style="myfuncti on(" 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.fieldnam e = '" & 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!

    Comment

    • C CSR
      New Member
      • Jan 2012
      • 144

      #3
      Correction:

      Response.write "<a id="" & myid & "" etc." produces <a id="ID1" etc.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        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:
        Code:
        $test = 1;
        echo "this is a $test"; // this is a 1
        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.
        Last edited by Dormilich; Jan 17 '12, 01:49 PM.

        Comment

        Working...