PHP variable variables

前端 未结 6 1262
别跟我提以往
别跟我提以往 2020-11-29 13:24

I want to store courseworks marks of n courseworks into n variables, such as cw1 and cw2 etc. Using variable variables how can I come with cw1, cw2 etc.

How can I d

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 13:49

    php > for ($i=0; $i<5; $i++)
             { ${"thing{$i}"} = $i; }
    php > echo $thing1;
    1
    php > echo $thing2;
    2
    php > echo $thing3;
    3
    

    Note that we're using the dollar sign around curly braces around a string.

提交回复
热议问题