PHP String Operator


 

PHP String Operator

In this tutorial we will study about string operator, string operators work only on the strings and there are only two kinds of operators are available in PHP "." and ".=", Examples in this tutorial will make it more clear.

In this tutorial we will study about string operator, string operators work only on the strings and there are only two kinds of operators are available in PHP "." and ".=", Examples in this tutorial will make it more clear.

String Operator:

In PHP there are only two operators are available for strings, first one is "." operator, and another is ".= " operator. Basically both does the same but with a little difference.

First operator concatenates the first value/variable with the next one and second operator appends the argument on the right side to left side of the operator.

Example:

<?php

$a="rose";

echo "Value of a is =". $a."<br/>";

$a.="india";

echo "After concatenation:<br/>";

echo "Value of a is =". $a;

?>

Output:

Value of a is =rose
After concatenation:
Value of a is =roseindia

Example:

<?php

$a="rose";

$b="india";

echo $a.$b;

?>

Output:

roseindia

Example:

<?php

echo "rose"."india";

?>

Output:

roseindia

Ads