Learn PHP Variables
Learn about PHP variables and the string and number data types.
StartKey Concepts
Review core concepts you need to learn to master this subject
Parsing Variables within PHP Strings
Reassignment of PHP Variables
Concatenating Strings in PHP
Appending a String in PHP
PHP Strings
PHP copying variables
PHP Variables
PHP String Escape Sequences
Parsing Variables within PHP Strings
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.
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory