donvo24600 2018-10-05 06:56
浏览 21
已采纳

PHP - 变量之外的数组名称

Is it possible to use php variable as a part of an array name. like this my arrays are Fday1, Fday2....but i cant go with the foreach keys beacause there are different counts of values for each array

$FdayArray = "Fday".$FdayKey;
array_push($FdayArray, $forecast);

the FdayKey would be a number between 1-9 How do I do this correctly?

  • 写回答

2条回答 默认 最新

  • duanbipu7601 2018-10-05 06:59
    关注

    You are looking for the variable variables feature of php.

    Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically. It takes the value of a variable and treats that as the name of a variable

    You would use

    array_push($$FdayArray, $forecast);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?