Page 1 of 1

Variable Concatenation

New postPosted: Thu Mar 27, 2008 10:36 pm
by Ranman
Code: [Select all] [Expand/Collapse] [Download] (Untitled)
   "Concatenation" means joining two into one


Q. What is the diffrence between " and '?
A. By example:

   This will print "This is 5 and text."

<?
$var = 5;
$text = "This is $var and text.";
echo $text;
?>


   This will print "This is $var and text."

<?
$var = 5;
$text = 'This is $var and text.';
echo $text;
?>


Example 1:

   The following prints "Some text then 15.2"

<?
$a = 15.2;
echo $b = "Some text then $a";
?>


Example 2:

   The following prints "10.5"

<?
$a = 4.3;
$b = 6.2;
$a += $b;
echo $a;
?>


Example 3:
    The following prints "10.5"

<?
$a = 4.3;
$b = 6.2;
$c = $a += $b;
echo $c;
?>


Example 4:

    The following prints "11"

<?
$a = 4.3;
$b = 6.2;
$c = 0.5;
$c += $a += $b;
echo $c;
?>


Example 5:

    The following prints "10"

<?
$a = 4.3;
$b = 6.2;
$c = -0.5;
$c += $a += $b;
echo $c;
?>



Re: Variable Concatenation

New postPosted: Mon Dec 23, 2013 12:24 pm
by Joplin
PHP Offical Documentation
String Operators