douyao6842 2013-05-24 19:05
浏览 95
已采纳

PHP中的多维数组 - 添加额外的维度?

$counter = 0;
foreach($dates as $dbRow) :
$datesExp[] = [$counter => array($dbRow->e_id => new DateTime($dbRow->l_date_expect))];
++$counter;
endforeach;

Using the above code, I'm trying to achieve is an array in format of:

0 => array(
    PK => DATE)
1 => array(
    PK2 => DATE2)
....etc

But what i'm getting with a var_dump is:

array (size=3)
    0 => 
    array (size=1)
      0 => 
        array (size=1)
          2 => 
            object(DateTime)[7]

Where is this: array (size=1) 0=> intermediate dimension coming from?

  • 写回答

2条回答 默认 最新

  • doucong4535 2013-05-24 19:10
    关注

    From here: $datesExp[] = [$counter => array($dbRow->e_id => new DateTime($dbRow->l_date_expect))];

    $datesExp[] = = add the following as an entry in this array

    [...]; = everything in here is an array

    array($dbRow->e_id => new DateTime($dbRow->l_date_expect)) = the innermost array

    should be

    $datesExp[$counter] = array($dbRow->e_id => new DateTime($dbRow->l_date_expect));

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

报告相同问题?

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)