Key Concepts

Review core concepts you need to learn to master this subject

Parsing Variables within PHP Strings

$my_var = "cat"; echo "There is one $my_var on the mat"; /* If there were three cats, then you can type: */ echo "There are three {$my_var}s on the mat "; /* The curly braces help to avoid confusion between the variable name and the letter s, so PHP does not consider the variable name as my_vars */

In PHP, variables can be parsed within strings specified with double quotes (").

This means that within the string, the computer will replace an occurence of a variable with that variable’s value.

When additional valid identifier characters (ie. characters that could be included in a variable name) are intended to appear adjacent to the variable’s value, the variable name can be wrapped in curly braces {}, thus avoiding confusion as to the variable’s name.

PHP Strings and Variables
Lesson 1 of 2

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo