Share on Google+Share on Google+

PHP String Operator

Advertisement
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

Advertisements

Posted on: March 20, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.