Difference in String/Variable Concatination

Discussion in 'PHP' started by ColorWP.com, Nov 18, 2011.

  1. #1
    I was wondering what is the difference between:
    print '{$var} some text';
    PHP:
    and
    print $var . ' some text';
    PHP:

     
    Solved! View solution.
    ColorWP.com, Nov 18, 2011 IP
  2. #2
    Your first example will output the string:

    {$var} some text

    The second will output the $var value followed by ' some text'.

    If you mean what's the difference with double quotes, like this:

    print "{$var} some text";
    PHP:
    ...with double quotes, they'll both print the variable value. Using double quotes in PHP however is slower as it checks for replacements (such as your $var variable) so the fastest to parse and easiest to read in most IDEs is this one:

    print $var . ' some text';
    PHP:
     
    mfscripts, Nov 18, 2011 IP