Thread: Assignment sign

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    231
    Rep Power
    16

    Assignment sign


    Hi,

    I saw a sign ".=" in a book but it was not explained. What does it do, please?

    Example

    Code:
    $data .= "$name ";
    $data .= "$value ";
    Thanks.
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3889
    It's equivalent to:
    Code:
    $data = $data . "$name ";
    Same with other operators. It's a shortcut to apply an operator to itself and also assign the result, e.g.:
    Code:
    $number +=5; # add 5 to $number
    $number *= 2; # double $number
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    231
    Rep Power
    16
    Thanks.
  6. #4
  7. 8 Miles
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    India
    Posts
    356
    Rep Power
    77
    Its appending $data with $name and $value.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2007
    Posts
    2
    Rep Power
    0

    perriod operator


    Originally Posted by soap
    Hi,

    I saw a sign ".=" in a book but it was not explained. What does it do, please?

    Example

    Code:
    $data .= "$name ";
    $data .= "$value ";
    Thanks.
    Hi,

    . [Period] is concatenation operator. It can be used in conjuction with assignment operators. Other arithmetic operators also can be used with assignment operatorf in conjunction.

    For ex:
    $a += 4;
    which means $a = $a +4

    Similarly.
    $a .= $b;
    is same as $a = $a.$b;

    Hope this is clear for you
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2007
    Posts
    2
    Rep Power
    0

    Now in ur problem with concatenation


    Originally Posted by wingsof5r
    Hi,

    . [Period] is concatenation operator. It can be used in conjuction with assignment operators. Other arithmetic operators also can be used with assignment operatorf in conjunction.

    For ex:
    $a += 4;
    which means $a = $a +4

    Similarly.
    $a .= $b;
    is same as $a = $a.$b;

    Hope this is clear for you



    Let us say ForEx:
    $data = "one";
    $name = "two";
    $value = "three";

    Now if ur script is like this
    $data .= "$name ";
    $data .= "$value ";

    Then the final output of ur $data will be "onetwo three "
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    231
    Rep Power
    16
    I got it. Thanks.

    Comments on this post

    • Matt1776 agrees : LoL .. thats what happens when you ask a simple syntax question ;0)

IMN logo majestic logo threadwatch logo seochat tools logo