AnyCompiler

Strings

PHP's concatenation operator is the single dot, . — not +, which is reserved for arithmetic. $first . " " . $last glues three pieces into one string. Single-quoted strings are taken almost completely literally (only \\ and \' are special inside them); double-quoted strings are different in one important way: any $variable written directly inside a double-quoted string is replaced with its value automatically, with no concatenation operator needed at all.

<?php
$first = "Ada";
$last = "Lovelace";
$full = $first . " " . $last;
echo $full, "\n";
$age = 36;
echo "Hello, $first! You are $age years old.\n";
echo strtoupper($full), "\n";
echo strlen($full), "\n";
echo str_replace("Lovelace", "Byron", $full), "\n";
Output
Ada Lovelace
Hello, Ada! You are 36 years old.
ADA LOVELACE
12
Ada Byron

"Hello, $first! You are $age years old.\n" interpolated both $first and $age in place — write the exact same text in single quotes and PHP would print the literal characters $first and $age instead, with no substitution at all. strtoupper(), strlen(), and str_replace() are three of the hundreds of string functions PHP's standard library ships — a direct consequence of PHP's web-templating roots, where generating and reshaping text is the entire job. Next: numbers and operators — arithmetic, and the single most notorious PHP gotcha: loose (==) vs strict (===) comparison, captured from a real, surprising diagnostic.

Practice exercise

Create $first = "Ada" and $last = "Lovelace", then echo "Hello, $first $last!" using double-quote interpolation, followed by a newline.