PHP variable variables

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

    You should really use an array, as Gumbo wrote:

    $cw = array();
    
    for($i = 0; $i < $n; ++$i) {
        $cw[] = $something;
    }
    

    However, a solution to your problem:

    for($i = 0; $i < $n; ++$i) {
        $tmp = 'cw' . $i;
        $$tmp = $something;
    }
    

提交回复
热议问题