Skip to content
PHP Logo

What is the syntax for creating new variables using double dollar signs ($$) in PHP?

Creating new variables using double dollar signs ($$) in PHP is known as variable variables. This allows you to dynamically create variable names based on the value of another variable. To create a variable variable, you simply use two dollar signs followed by a variable name inside another variable. This can be useful in situations where you need to generate variable names dynamically.

php
// Example of creating a variable variable
$varName = 'newVariable';
$$varName = 'Hello, World!';

// Accessing the dynamically created variable
echo $newVariable; // Output: Hello, World!