A little dab'll do ya
Code Snippets
Variable Variables
<?php
$var1 = 'nameOfVariable';
$nameOfVariable = 'This is the value I want!';
echo $$var1;
?><?php
$var1 = 'nameOfVariable';
$nameOfVariable = 'This is the value I want!';
echo $$var1;
?>
Mind you can also do that with more $s:
And you can use curly brackets:
Mind you can also do that with more $s:
And you can use curly brackets:
no
Wow! I never even knew about this. Might be a pretty great asset in the future.
how? ^
I would like to ask a question, How to show variable in between the text.
E.g., I have
“var1 = $_POST['username'];”
I want to show it something like this,
“Hello [username]“.
How to do it?
I tried this but it didn’t work,
“echo Hello $var1;”
Please help me regarding this.
$var1=$_POST’username’];
echo “Hello [" . $var1 . "]“;
Try like this
$var=$_POST['username'];
echo ‘Hello['.$var.']‘;
If you need to create variables from an array there are two options.
The first uses php extract()
The second options which will give you more control is php list()