Variable parsing: Simple syntax

<?php
$juice = "apple";

echo "He drank some $juice juice.".PHP_EOL;
// Invalid. "s" is a valid character for a variable name, but the variable is $juice.
echo "He drank some juice made of $juices.";
// Valid. Explicitly specify the end of the variable name by enclosing it in braces:
echo "He drank some juice made of ${juice}s.";
?>

If a dollar sign ($) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name.

It provides a way to embed a variable, an array value, or an object property in a string with a minimum of effort.

The simple syntax is the most common and convenient.

Variable parsing: Simple syntax — Structure map

Clickable & Draggable!

Variable parsing: Simple syntax — Related pages: