$counter = 0;
foreach($dates as $dbRow) :
$datesExp[] = [$counter => array($dbRow->e_id => new DateTime($dbRow->l_date_expect))];
++$counter;
endforeach;
使用上面的代码,我试图实现的是一个数组的格式:
0 => array(
PK => DATE)
1 => array(
PK2 => DATE2)
....etc
但是我用var_dump得到的是:
array (size=3)
0 =>
array (size=1)
0 =>
array (size=1)
2 =>
object(DateTime)[7]
Where is this:array (size=1)
0=>
中间维度从何而来?
From here: $datesExp[] = [$counter => array($dbRow->e_id => new DateTime($dbRow->l_date_expect))];
$datesExp[] =
=在数组中添加以下条目
[...];
=这里的一切都是数组
array($dbRow->e_id => new DateTime($dbRow->l_date_expect))
=最里面的数组
$datesExp[$counter] = array($dbRow->e_id => new DateTime($dbRow->l_date_expect));
试试这个,不需要单独的计数器,不需要外部大括号[..]
$datesExp[] = array($dbRow->e_id => new DateTime($dbRow->l_date_expect));