-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
  • 42,835
  • 20
  • 145
  • 262
Xhynk
  • 12,900
  • 8
  • 31
  • 68

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,334
  • 1
  • 27
  • 32
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
  • 311,322
  • 76
  • 447
  • 566
-1

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

Jonathan
  • 2,908
  • 3
  • 23
  • 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