Sometimes, we want to use braces with dynamic variable names in PHP.
In this article, we’ll look at how to use braces with dynamic variable names in PHP.
How to use braces with dynamic variable names in PHP?
To use braces with dynamic variable names in PHP, we wrap our variable name expression with braces.
For instance, we write
${"file" . $i} = file($filelist[$i]);
to create variables with "file" . $i
inside the braces.
$i
will be replaced with the actual value to form the variable name.
Conclusion
To use braces with dynamic variable names in PHP, we wrap our variable name expression with braces.