-2

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

Consider this code example:

{
    $n1 = ucfirst(strtolower($n1));
    $n2 = ucfirst(strtolower($n2));
    $n3 = ucfirst(strtolower($n3));
    return $n1 . " " . $n2 . " " . $n3;
}

My book says the code will display:

William Henry Gates (each name is the value of the variables)

So what do the . in between the quotes and the next variable do? I must have read over it, and I look back for it, but I couldn't find it.

Community
  • 1
  • 1
PolarisUser
  • 719
  • 2
  • 7
  • 18

3 Answers3

4

It concatenates (merges) strings

bartvanraaij
  • 323
  • 1
  • 8
4

Concatenation

Since you are trying to return the variable $n1 with a space $n2 with another space and $n3

You can also check String Operator from PHP Manual for more information about this

One of the example to use the . operator or refer to String Operator from PHP manual

<?php
 $a = "Hello ";
 $b = $a . "World!"; // now $b contains "Hello World!"

 $a = "Hello ";
 $a .= "World!";     // now $a contains "Hello World!"
?>
karthikr
  • 97,368
  • 26
  • 197
  • 188
Ali
  • 9,997
  • 20
  • 70
  • 105
2

The . operator concatenates strings.

The code converts $n1, $n2, and $n3 into lowercase, then capitalizes the first letter, then combines all three names together with a space between each name.

Tuanderful
  • 1,337
  • 1
  • 10
  • 13