PHP String Operators

PHP's string operato provide a convenient way in which to concatenate strings together. There are two such operators, including the concatenation operator (.) and the concatenation assignment operator (.=).

Note : To concatenate means to combine two or more objects together to form one single entity.

Example Label Outcome
$a = "abc"."def"; Concatenation $a is assigned the string abcdef
$a .= "ghijkl"; Concatenation-assignment $a equals its current value concatenated with "ghijkl"

Here is an example involving string operators:


<?php
 // $a contains the string value "Spaghetti & Meatballs";
 $a = "Spaghetti" . "& Meatballs";
?>
<?php
 $a .= "are delicious."
 // $a contains the value "Spaghetti & Meatballs are delicious."
?>

The two concatenation operators are hardly the extent of PHP's string-handling capabilities.





Content