PHP String Operators

Description

There are only two string operators in PHP: concatenation and shorthand concatenation. Both are shown in the following table.

Operator Name Description
. Concatenation Returns the second value appended to the first: $a . $b
.= Shorthand concatenation Appends the second value to the first: $a .= $b

Example

These operators are used to join strings together, like this:


<?PHP/*  w w w .j a v a  2 s  . c o m*/
      $first = "Hello, "; 
      $second = "world! from java2s.com"; 

      // join $first and $second; assign to $third 
      $third = $first . $second; 
      // $third is now "Hello, world!" 

      $first .= " officer!"; 
      // $first is now "Hello, officer!" 
?>




















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition