SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question What does ".=" mean in PHP?

    ...And how do you use it?

    Once again, that's the ".=" (without the quotes), and how do you use it...? From what I have read, it is the "String Concatenation" operator, but I have the hardest time understanding what exactly it does...

    I saw it in some code I was messing with. See the following:

    PHP Code:
    $output .= page_tree($p$r['levels'], $c_p$r); 

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $a 'hello ';
    $b 'george';

    echo 
    $a# hello
    echo $b# george

    $a .= $b# virtually same as $a = $a . $b;

    echo $a# hello george;
    echo $b# george; 
    Does this make it more clear? Concantenating means sticking two strings next to each other.

    In your code, the page_tree is a function that will probably return some sort of string, which is then attached to the end of $output.

  3. #3
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    [PHP]
    Concantenating means sticking two strings next to each other.
    That, right there, made it better. I think I understand now, though, it will take some time to be ingrained into my thick skull...

  4. #4
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $bunchastuff 'hello'//sets the first $bunchastuff
    $bunchastuff .= 'world'//adds more stuff to $bunchastuff
    $bunchastuff .= 'I like sunshine'//adds even more stuff to $bunchastuff

    echo $bunchastuff// outputs hello world I like sunshine 
    .= adds more variable values to the initial variable declared and allways use technical sounding variables like $bunchastuff.

    (thats how I learned lol)
    What I lack in acuracy I make up for in misteaks

  5. #5
    Team SitePoint santouras's Avatar
    Join Date
    Jul 2006
    Location
    planet earth
    Posts
    276
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    PHP Code:
    $a 'hello ';
    $b 'george';

    echo 
    $a# hello
    echo $b# george

    $a .= $b# virtually same as $a = $a . $b;

    echo $a# hello george;
    echo $b# george; 
    Does this make it more clear? Concantenating means sticking two strings next to each other.

    In your code, the page_tree is a function that will probably return some sort of string, which is then attached to the end of $output.
    actualy $a would echo "hellogeorge"
    my utility belt tells me its to the bar batman

    read the manual then google it then do a search THEN post....

  6. #6
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "$a @= $b" means "$a = $a @ $b", where '@' = any binary operator.

  7. #7
    SitePoint Member iDemonix's Avatar
    Join Date
    Oct 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by santouras View Post
    actualy $a would echo "hellogeorge"
    It wouldn't, there's a space after hello in the $a variable.

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    pwned!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •