0

如何将属性添加到数组对象变量?假设我有这样的变量对象:

    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] => [author_email] 下面的 1。是否可以?

4

1 回答 1

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
        )

)
于 2012-12-11T04:01:38.223 回答