Skip to content

PHP String Interpolation

Syntax

String interpolation in PHP allows embedding variables directly within double-quoted strings.

$interpolatedString = "This is a value: $value";

Example

// Interpolating variables in a string
$name = "John";
echo "Hello, $name!"; // Outputs: Hello, John!
// Using curly braces for complex expressions
$items = 5;
echo "You have {$items} items in your cart."; // Outputs: You have 5 items in your cart.