我想根据 if 语句将 key=>value 对添加到现有数组中。但它不断添加 key=>value 对作为新索引。
这是我的代码:
foreach ($messageRepo as $oneMessage) {
$calculatedTime = $oneMessage->getTimeToLive();
$creationTime = $oneMessage->getCrdate();
$calculatedTimes = $this->androidService->renderFormat($calculatedTime);
$expiringDate = $creationTime + $calculatedTime;
$ausgabe[] = array(
'Time' => key($calculatedTimes),
'Format' => current($calculatedTimes),
'Title' => $oneMessage->getMessageTitle(),
'Text' => $oneMessage->getMessageText(),
);
if (time() > $expiringDate) {
array_push($ausgabe[]['Expired'], $expiringDate);
} else {
array_push($ausgabe[]['Expiring'], $expiringDate);
}
}
转储说:
array(60 items)
0 => array(4 items)
Time => 0 (integer)
Format => 'Stunden' (7 chars)
Title => '3 wochen total neu' (18 chars)
Text => 'dfdsfsdf fgdsfgdsgf' (19 chars)
1 => array(1 item)
Expired => NULL
但我想Expired => NULL
作为原始索引中的字段而不是新索引。