【发布时间】:2015-05-09 02:20:33
【问题描述】:
我正在从数据库中获取包含数据的 pdo 对象。现在,当我 foreach 这些数据时,我想添加额外的键值,但这不起作用。
foreach ($deliveryCompanies as $k=>$v) {
$k->test = 'test';
}
返回 类型:错误异常 代码:2 消息:尝试分配非对象的属性
对象看起来像这样
Array
(
[0] => stdClass Object
(
[delivery_id] => 2
[delivery_location_id] => 34
[delivery_category_id] => 1
)
[1] => stdClass Object
(
[delivery_id] => 4
[delivery_location_id] => 34
[delivery_category_id] => 1
)
)
1
【问题讨论】: