PHP String Operators
In this chapter you will learn:
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/* ja 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!"
?>
Next chapter...
What you will learn in the next chapter:
- What is Ternary Operator
- Syntax for PHP Ternary Operator
- Note for PHP Ternary Operator
- Example - Convert between ternary operator and if statement