How do I insert a variable into a PHP array?

前端 未结 3 2263
滥情空心
滥情空心 2021-02-20 05:10

I have looked for some responses on the web, but none of them are very accurate.

I want to be able to do this:

$id = \"\" . $result [\"id\"] . \"\";
$i         


        
3条回答
  •  南旧
    南旧 (楼主)
    2021-02-20 05:40

    Just don't put it in quotes:

    $id = $result["id"];
    $info = array($id, 'Example');
    echo $info[0];
    

    Alternatively, if you use double quotes rather than single quotes, then it will be interpolated (which also results in it being converted to a string):

    $id = $result["id"];
    $info = array("$id", 'Example');
    echo $info[0];
    

提交回复
热议问题