PHP - Variable inside variable?
$bookA = "123"; $开发者_C百科crack = "A";
I want to do something similar to this:
echo $book$crack;
Such that the output is 123.
What is the correct syntax for the echo command?
Thanks.
echo ${"book" . $crack};
These are called variable variables, but you should use arrays instead.
$varname = 'book'.$crack;
echo $$varname;
You might want to use an associative array.
For instance:
$book = array();
$book["A"] = "Some Book";
$crack = "A";
//Later
echo $book[$crack];
This will work:
$bookA = "123";
$crack = "A";
$var = "book$crack";
echo $$var;
Try the following:
echo ${book.$crack};
It works for me.
精彩评论