Introduction
We use the string concatenation operator to join two or more pieces of text together into one longer text.
We use the string concatenation operator to join two or more pieces of text together into one longer text.
$fullString = $string1 . $string2;
$greeting = "Hello, " . "world!";
$fullName = $firstName . " " . $lastName;$file = "photo" . ".jpg";
This program joins first and last names with a space, then prints the full name and a greeting.
<?php $firstName = "Jane"; $lastName = "Doe"; $fullName = $firstName . " " . $lastName; echo "Full name: " . $fullName . "\n"; $greeting = "Hello, " . $fullName . "!"; echo $greeting . "\n"; ?>
Remember to add spaces manually if you want spaces between words.
The concatenation operator (.) automatically converts numbers and other non-string values to strings.
The dot (.) joins strings together in PHP.
You can join many strings by chaining dots.
Spaces or other characters must be added explicitly if needed.
.) operator do in PHP?$a and $b in PHP?$greeting = "Hello"; $name = "Alice"; echo $greeting . ", " . $name . "!";
$first = "Good"; $second = "Morning"; echo $first + " " + $second;
$firstName and $lastName with a space between them. Which code correctly does this in PHP?Pass the test and this pattern moves unknown