6

Possible Duplicate:
What does the 'period' character (.) mean if used in the middle of a php string?

Why are the periods included in the code that follows?

require("mod/" . $modarrayout . "/bar.php");

Obviously, it's because the variable is between strings, but shouldn't the quotes have taken care of that? PHP

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tom
  • 135
  • 2
  • 9

3 Answers3

8

In PHP, the period is the concatenation operator. Putting the periods in tells PHP to concatenate "mod/" to $modarrayout and then concatenate the resulting string to "/bar.php". See page String Operators.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Grayson
  • 84,103
  • 24
  • 152
  • 189
2

The following is the same in this case:

require("mod/$modarrayout/bar.php");

Using string concatenation is a different approach to string building.

I suggest reading the manual page on strings.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side.

Read: String Operators

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Germán Rodríguez
  • 4,284
  • 1
  • 19
  • 19