Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

String concatenation with assignment (.=)

Build up a label in the same variable by appending the text on the right.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$value .= $operand

Build up a label in the same variable by appending the text on the right. Each fragment follows the fragments already stored.

The text of the right operand follows the text of the left operand. An empty string adds no bytes. Supply any separator explicitly.

Evaluation

  • $value = "A"; $value .= "07"; → "A07"
  • $value = "A"; $value .= ""; → "A"
  • $value = "3"; $value .= "5"; → "35"

Examples

<?php
$value = "A";
$value .= "07";
echo json_encode($value), PHP_EOL;

$value = "A";
$value .= "";
echo json_encode($value), PHP_EOL;

$value = "3";
$value .= "5";
echo json_encode($value), PHP_EOL;

Result

"A07"
"A"
"35"

Sources