[英]php , creating a new attribute in sql results array
The following code keeps returning the error 以下代码不断返回错误
Warning: Attempt to assign property of non-object
警告:尝试分配非对象的属性
This happens during the line $a->tomorrowDate = array("dateTomorrow" => $invoiceNextDay); 这发生在$ a-> tomorrowDate = array(“ dateTomorrow” => $ invoiceNextDay)行中;
foreach ($resultInvoices as &$a) {
$invoiceDate = date_create_from_format('d/m/Y', $a['date']);
$invoiceNextDay = $invoiceDate->modify('+1 day');
$invoiceNextDay->format('Ymd');
$a->tomorrowDate = array("dateTomorrow" => $invoiceNextDay);
$a['date']=$invoiceDate->format('Ymd');
}
What is wrong with that line? 那条线怎么了?
I found out my issue. 我发现了我的问题。
foreach ($resultInvoices as &$a) {
$invoiceDate = date_create_from_format('d/m/Y', $a['date']);
$a['date']=$invoiceDate->format('Ymd');
$invoiceNextDay = $invoiceDate->modify('+1 day');
$invoiceNextDay->format('Ymd');
$a['tomorrowDate'] = $invoiceNextDay;
}
Essentially, what I tried before was for objects, whilst now, its specific to arrays. 本质上,我之前尝试过的对象是对象,而现在,它是特定于数组的。 $a['tomorrowDate'] = $invoiceNextDay;
$ a ['tomorrowDate'] = $ invoiceNextDay; This will create a new element in the array with attribute tomorrowDate and then assign it the value.
这将在数组中创建一个带有明日属性的新元素,然后为其分配值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.