0

How can I add the property to the array object variables? Let's say I have variable object like this:

    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] => [email protected]
        )

)

What I want here, is to add new properties eg. [site_id] => 1 below the [author_email]. Is it possible?

1
  • Object properties are not specifically ordered (though array keys are...) but you have an object inside an array with one index [0] so $yourvar[0]->site_id = 1; Commented Dec 11, 2012 at 3:57

1 Answer 1

2

This is what you have basically (an array with an object at the 0 index)...

$array = array(new stdclass);
print_r($array);

This gives you

 Array (
    [0] => stdClass Object
        (
        )

)

Now you want to add some property to that object...

$array[0]->site_id = 1;
print_r($array);

This will give you

Array
(
    [0] => stdClass Object
        (
            [site_id] => 1
        )

)
Sign up to request clarification or add additional context in comments.

1 Comment

@MuthuKumaran Please point me to any document that provide information how to set as correct answer. I just see the option "was this post useful to you : yes | no"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.