variable difference

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepaks85
    New Member
    • Aug 2006
    • 114

    #1

    variable difference

    Dear Friends,

    I have these script......


    [PHP]$line = $data;

    //and

    $line. = $data;[/PHP]

    Can anybody tell me that If I want to pass the value of $data to $line then What is the difference between both of them.

    Thanks
    Deepak
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    In PHP strings, the dot acts like the plus sign in most programming languages.
    That is if you put .= between two string variables, the second one will be added to the first one.
    If you however just use the = sign, the second one will override the first one.

    Example:
    [PHP]
    $var1 = "Hello";
    $var2 = "World";

    $var3 = $var1;// = Hello
    $var3 .= $var2;// = HelloWorld
    $var3 = $var1 . $var2;// = HelloWorld
    $var3 = $var1 . " " . $var2;// = Hello World
    [/PHP]

    Note: Your second line would probbly cause a parse error, because there is a space between the dot and the equal sign. That is not allowed.

    Comment

    • deepaks85
      New Member
      • Aug 2006
      • 114

      #3
      Thanks very much Atli....

      Comment

      Working...