Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the .= operator mean in PHP?

I have a variable that is being defined as

$var .= "value"; 

How does the use of the dot equal function?

like image 379
codacopia Avatar asked Feb 13 '13 04:02

codacopia


People also ask

What is an operator in PHP?

Operators are used to perform operations on variables and values. PHP divides the operators in the following groups: Arithmetic operators. Assignment operators. Comparison operators.

What does the :: operator do in PHP?

In PHP, the double colon :: is defined as Scope Resolution Operator. It used when when we want to access constants, properties and methods defined at class level. When referring to these items outside class definition, name of class is used along with scope resolution operator.

What does <=> mean in PHP?

The spaceship operator <=> is the latest comparison operator added in PHP 7. It is a non-associative binary operator with the same precedence as equality operators ( == , !=

What does && means in PHP?

PHP && Operator The logical operator && returns: TRUE only if both of its operands evaluate to true. FALSE if either or both of its operands evaluate to false.


2 Answers

It's the concatenating assignment operator. It works similarly to:

$var = $var . "value"; 

$x .= differs from $x = $x . in that the former is in-place, but the latter re-assigns $x.

like image 78
Blender Avatar answered Oct 02 '22 00:10

Blender


This is for concatenation

$var  = "test"; $var .= "value";  echo $var; // this will give you testvalue 
like image 34
Prasanth Bendra Avatar answered Oct 02 '22 00:10

Prasanth Bendra