如何将属性添加到数组对象变量中? 假设我有这样的变量对象:
Array
(
[0] => stdClass Object
(
[category] => Nuklir
[id] => 715
[title] => Testing Article Nuklir
[alias] => testing-article-nuklir
[title_alias] =>
[introtext] => <p><span style="color: #666666; font-family: 'Lucida Grande', Arial, sans-serif; font-size: 13px; line-height: 19px;" mce_style="color: #666666; font-family: 'Lucida Grande', Arial, sans-serif; font-size: 13px; line-height: 19px;">Vivamus libero eros, dictum id aliquam in, tristique id sapien. Maecenas rhoncus malesuada aliquet. Morbi vulputate vulputate mauris quis condimentum. Ut ut ligula et mauris accumsan tristique ut nec lacus.</span></p><p><span style="color: #666666; font-family: 'Lucida Grande', Arial, sans-serif; font-size: 13px; line-height: 19px;" mce_style="color: #666666; font-family: 'Lucida Grande', Arial, sans-serif; font-size: 13px; line-height: 19px;">Vivamus libero eros, dictum id aliquam in, tristique id sapien. Maecenas rhoncus malesuada aliquet. Morbi vulputate vulputate mauris quis condimentum. Ut ut ligula et mauris accumsan tristique ut nec lacus.</span></p><p><span style="color: #666666; font-family: 'Lucida Grande', Arial, sans-serif; font-size: 13px; line-height: 19px;" mce_style="color: #666666; font-family: 'Lucida Grande', Arial, sans-serif; font-size: 13px; line-height: 19px;">Vivamus libero eros, dictum id aliquam in, tristique id sapien. Maecenas rhoncus malesuada aliquet. Morbi vulputate vulputate mauris quis condimentum. Ut ut ligula et mauris accumsan tristique ut nec lacus.</span><br /></p>
[fulltext] =>
[sectionid] => 7
[state] => 1
[catid] => 25
[created] => 2012-12-10 07:51:03
[created_by] => 110
[created_by_alias] =>
[modified] => 0000-00-00 00:00:00
[modified_by] => 0
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[publish_up] => 2012-12-10 07:51:03
[publish_down] => 0000-00-00 00:00:00
[hits] => 0
[images] =>
[urls] =>
[ordering] => 1
[metakey] =>
[metadesc] =>
[access] => 0
[slug] => 715:testing-article-nuklir
[catslug] => 25:nuklir
[readmore] => 0
[author] => migrasi
[usertype] => Super Administrator
[groups] => Public
[author_email] => test@yahoo.com
)
)
我想要的是添加新属性,例如。 [site_id] =&gt; 1位于[author_email]下面。有可能吗?
答案 0 :(得分:2)
这基本上就是你所拥有的(一个对象在0索引处的数组)......
$array = array(new stdclass);
print_r($array);
这会给你
Array (
[0] => stdClass Object
(
)
)
现在你要为该对象添加一些属性......
$array[0]->site_id = 1;
print_r($array);
这会给你
Array
(
[0] => stdClass Object
(
[site_id] => 1
)
)