String Operators
×
Home Courses Community Support
String Operators

As you are familiar with String and know how to work with string. So let's proceed with String Operators. String Operators are as below-

Concatenation Operator (.)

Concatenation Operator is used to put two string values together. Unlike other languages we use Dot(.) to put the values together. We are using dot because PHP is loosely typed language. We don’t need to define the data type, that’s why if we use + then it will be taken as integer otherwise string, that doesn’t matter what is the data type.

See below example-

<?php
$txt1 = "I am Geeku. ";
$txt2 = "I am here to teach you.";
echo $txt1.$txt2; //This operator will print both value together. 
?>

Output:

I am Geeku. I am here to teach you.


Concatenation assignment (.=)

Cancatenation assigment is used to append one variable's string value to another. For example if we want to get same output as in previous example and don't want to use $txt2 in echo, then we will have to use Cancatenation assignment.

See below code-

<?php
$txt1 = "I am Geeku. ";
$txt2 = "I am here to teach you.";
$txt1 .= $txt2;
echo $txt1;
?>

Output:

I am Geeku. I am here to teach you.

 

← Preview

Logical Operators

Next →

Array Operators

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App