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 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题