PHP variable variables

前端 未结 6 1264
别跟我提以往
别跟我提以往 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:46

    Variable variables work in this way

    $var = "foo";
    $$var = "bar";
    
    echo $foo; // bar
    

    But i do not recommend doing this, since what if the value of $var changes, then you can no longer print out the 3rd line in this code.

    If you could elaborate more on what you want to do i think we could help you more.

提交回复
热议问题