www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to Get Value from stdClass Object

  1. #1
    Join Date
    Oct 2013
    Posts
    11

    How to Get Value from stdClass Object

    How to get value from class
    Code:
    stdClass Object
    (
        [user] => stdClass Object
            (
                [name] => website
                [likes] => 0
                [following] => 1
                [default_post_format] => html
                [blogs] => Array
                    (
                        [0] => stdClass Object
                            (
                                [name] => alexa
                                [url] => http://alexa.com/
                                [followers] => 0
                                [primary] => 1
                                [title] => Untitled
                                [description] => 
                                [admin] => 1
                                [updated] => 0
                                [posts] => 0
                                [messages] => 0
                                [queue] => 0
                                [drafts] => 0
                                [share_likes] => 1
                                [ask] => 
                                [tweet] => N
                                [facebook] => N
                                [facebook_opengraph_enabled] => N
                                [type] => public
                            )
    
                        [1] => stdClass Object
                            (
                                [name] => google
                                [url] => http://google.com/
                                [followers] => 0
                                [primary] => 
                                [title] => google
                                [description] => 
                                [admin] => 1
                                [updated] => 0
                                [posts] => 0
                                [messages] => 0
                                [queue] => 0
                                [drafts] => 0
                                [share_likes] => 
                                [ask] => 
                                [tweet] => N
                                [facebook] => N
                                [facebook_opengraph_enabled] => N
                                [type] => public
                            )
    
                        [2] => stdClass Object
                            (
                                [name] => yahoo
                                [url] => http://yahoo.com/
                                [followers] => 0
                                [primary] => 
                                [title] => yahoo
                                [description] => 
                                [admin] => 1
                                [updated] => 0
                                [posts] => 0
                                [messages] => 0
                                [queue] => 0
                                [drafts] => 0
                                [share_likes] => 
                                [ask] => 
                                [tweet] => N
                                [facebook] => N
                                [facebook_opengraph_enabled] => N
                                [type] => public
                            )
    
                    )
    
            )
    
    )
    I trying to use this code, but found error,
    the problem on numbering [0] [1] [2]

    I want to get [name] =>???

    PHP Code:
    $userid=$me->user->blogs;    
        for(
    $i 0$i count($userid); $i++){
             echo 
    $me->user->blogs->$i->name."<br />";
        } 
    Please advice.

    Thnk
    Last edited by NogDog; 10-29-2013 at 11:04 AM. Reason: added [code] and [php] tags

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,530
    PHP Code:
    foreach ($me->user->blogs as $name) {
        echo 
    $name."</ br>\n";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2013
    Posts
    11
    Quote Originally Posted by NogDog View Post
    PHP Code:
    foreach ($me->user->blogs as $name) {
        echo 
    $name."</ br>\n";

    not success

    shown Array

    I am try to use

    foreach ($me->user->blogs as $name) {
    echo $name->0->name."</ br>\n";
    }

    also
    foreach ($me->user->blogs as $name) {
    echo $name[0][name]."</ br>\n";
    }
    not success also

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,530
    My bad, try this:
    PHP Code:
    foreach ($me->user->blogs as $data) {
        echo 
    $data->name."</ br>\n";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Oct 2013
    Posts
    11

    Lightbulb Solved ....

    Quote Originally Posted by NogDog View Post
    My bad, try this:
    PHP Code:
    foreach ($me->user->blogs as $data) {
        echo 
    $data->name."</ br>\n";

    Thank you so much.
    I have been this answer all this days

    now I can grab the name, first I am confused about number [0]or [1] got error

    but now it fixed

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles