-1

Possible Duplicate:
Reference - What does this symbol mean in PHP?

I can't seem to find the answer of what the difference is between

somephp" + foo + "morephp

and

somephp" . foo . "morephp

Dreamweaver recognizes both as syntactically correct. I just need an article link or explanation as the difference between them? Thanks! :)

My specific circumstance is I've got - CHILD_POS - which needs to be inserted into a static string. Basically... :

echo 'some stuff goes here' +/. CHILD_POS +/. 'some more stuff goes here';

I'm unsure whether to use (+) or (.)

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Xhynk
  • 13,513
  • 8
  • 32
  • 69

3 Answers3

13

The . character is specifically for string concatenation in PHP. The + symbol is for math operations.

See the appropriate PHP manual pages:

String Operators

Arithmetic Operators

WWW
  • 9,734
  • 1
  • 29
  • 33
6

Using + will attempt to convert the string to a number, usually resulting in 0.

Using . will concatenate the strings, which is what you almost always want.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
-1

You can't use + for string concatenation in php. So no difference so discuss.

Jonathan
  • 2,968
  • 3
  • 24
  • 36
  • 2
    I guess I shouldn't have said + "doesn't exist" PHP. It does of course exist in math operations but you cant use both + and . for string concatenation which Alex seems to have thought. That's what i meant. – Jonathan Jul 23 '12 at 16:48
  • 1
    I appreciate the clarification - as I did think both could be used for strings. – Xhynk Jul 23 '12 at 16:51
  • 1
    +1 IMO this has been unfairly downvoted; it's an entirely true statement. – Ernest Friedman-Hill Jul 24 '12 at 14:32
  • @ErnestFriedman-Hill It was downvoted before it was edited. I have reversed my vote in response. – gcochard Jul 26 '12 at 15:56