Web Design Forum: What does .= mean in PHP? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

What does .= mean in PHP? Rate Topic: -----

#1 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 05 February 2012 - 09:00 PM

Hello,

I've got what is probably a very simple question but, it has stumped me!

Could someone please explain to me what .= means when coding php?

Many thanks,

Gary :)
0

#2 User is offline   Mythriel 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 78
  • Joined: 15-June 10
  • Reputation: 4
  • Gender:Male
  • Experience:Nothing
  • Area of Expertise:Web Developer

Posted 05 February 2012 - 09:44 PM

Concatenate to a string.
e.g:
$var = "This is a "; 
$var .= "test demonstration";
echo $var; //prints This is a test demonstration  

1

#3 User is offline   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 05 February 2012 - 10:17 PM

The assignment operator is a shorthand for
$a .= 'some string';

is the equivalent of
$a = $a . 'somestring';

See here for more information
1

#4 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 06 February 2012 - 09:15 PM

Thanks very much. So it's kind of like adding a bit more onto the end of the string then?
0

#5 User is offline   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 06 February 2012 - 09:20 PM

Yes for a string using the . before the = will do that, but there are others you will find useful

$a += 50;
Adds 50 to $a
Equivalent to
$a = $a + 50;

$a -= 50;
subtracts 50 from $a
Equivalent to
$a = $a - 50;

It's really just a useful shorthand

You can do the same with all of the other operators, like *, / and % too
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users