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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?