CHAPTER 28

image

Advanced Variables

In addition to being a container for data, PHP variables have some other features that will be examined in this chapter. These are features that are not commonly used but are good to know about.

Curly syntax

A variable name can be explicitly specified by enclosing it in curly brackets. This is known as curly or complex syntax. To illustrate, the following code will output the variable even though it appears in the middle of a word.

$fruit = 'Apple';echo "Two {$fruit}s"; // "Two Apples"

More importantly, the curly syntax is useful for forming variable names out of expressions. Consider the following code which uses ...

Get PHP Quick Scripting Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.