-2

What is the difference between .= and = ? What is .= used for?

Example:

<?php
$file = fopen('WERK-tabelle.csv', 'r') or die('error');

$yml = '';
$keys = [
    blabla, code, php
];

while (($values = fgetcsv($file, 0, ';')) !== FALSE) {
    $yml .= "<br>";
    $arr = array_combine($keys, $values);
    foreach ($arr as $key => $value) {
        $yml .= "<br>{$key}{$value}\n";
    }
}
Z. Dmitry
  • 321
  • 4
  • 22
  • 2
    Also see [this question](https://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php?rq=1) for a more complete list of PHP operators. – Phylogenesis Jul 24 '17 at 12:39

1 Answers1

5

.= is simply used to add something to the end of a string, without overwriting it.

Example 1 (without .=):

$myvar = "Hello";
$myvar = "Peter";
echo $myvar; //Will output "Peter"

Example 2 (With .=):

$myvar = "Hello";
$myvar .= "Peter";
echo $myvar; //Will output "HelloPeter" (concatenated string)
BenRoob
  • 1,662
  • 5
  • 22
  • 24
Twinfriends
  • 1,972
  • 1
  • 14
  • 34