Skip to content
PHP Logo

What is the correct syntax for combining two variables with text in PHP?

When combining variables with text in PHP, you can use the concatenation operator (.) to join them together. This allows you to create a string that includes both the variable values and additional text. Simply place the variables and text within double quotes and use the concatenation operator to combine them.

php
// Example of combining two variables with text in PHP
$firstName = "John";
$lastName = "Doe";

// Combine variables with text using the concatenation operator
$fullName = $firstName . " " . $lastName;

echo "Full Name: " . $fullName;