我有一个 stdClass 数组。该数组的输出如下:
Array
(
[0] => stdClass Object
(
[vendor_id] => 1
[user_id] => 1
[date_created] => 2013-06-12 16:48:38
[date_edited] =>
[status] => active
[user_firstname] => Stuart
[user_surname] => Blackett
)
)
我想做的是向这个 stdClass 添加两个变量。它们是“total_bookings”和“total_venues”;
我目前正在遍历结果,然后计数以创建总数。我想将这两个变量添加到该 stdClass 数组的末尾。
我的PHP如下:
$vendors = $this->po_model->get_all_vendors();
$this->template->set('total_vendors', count($vendors));
$count = 0;
foreach($vendors as $vendor)
{
$count++;
$total_venues = $this->po_model->get_count_venues($vendor->user_id);
$total_bookings = $this->po_model->get_count_bookings($vendor->user_id);
$vendors[$count]['total_venues'] = $total_venues;
$vendors[$count]['total_bookings'] = $total_bookings;
}
但是,当我 var_dump 时,我的 Array 看起来像这样:
Array
(
[0] => stdClass Object
(
[vendor_id] => 1
[user_id] => 1
[date_created] => 2013-06-12 16:48:38
[date_edited] =>
[status] => active
[user_firstname] => Stuart
[user_surname] => Blackett
)
[1] => Array
(
[total_venues] => 6
[total_bookings] => 14
)
)
所以我的问题是,如何将 total_venues 和 total_bookings 添加到 stdClass()?
谢谢