PHP - Variable inside variable?

前端 未结 6 1154
梦毁少年i
梦毁少年i 2021-01-18 07:00

$bookA = \"123\"; $crack = \"A\";

I want to do something similar to this:

echo $book$crack;

Such that the output is 123

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 07:12

    You might want to use an associative array.

    For instance:

    $book = array();
    $book["A"] = "Some Book";
    $crack = "A";
    
    //Later
    echo $book[$crack];
    

提交回复
热议问题