SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing properties in an array

    Hello,

    I have an array of objects as so

    stdClass Object ( [as_of] => Sat, 21 Feb 2009 15:03:38 +0000 [trends] => Array ( [0] => stdClass Object ( [name] => #pcto09 [url] => http://search.twitter.com/search?q=%23pcto09 ) [1] => stdClass Object ( [name] => #tots [url] => http://search.twitter.com/search?q=%23tots ) [2] => stdClass Object ( [name] => #iba09 [url] => http://search.twitter.com/search?q=%23iba09 ) [3] => stdClass Object ( [name] => #UG5 [url] => http://search.twitter.com/search?q=%23UG5 ) [4] => stdClass Object ( [name] => Dollhouse [url] => http://search.twitter.com/search?q=Dollhouse ) [5] => stdClass Object ( [name] => #backflick [url] => http://search.twitter.com/search?q=%23backflick ) [6] => stdClass Object ( [name] => Chandra Levy [url] => http://search.twitter.com/search?q=%22Chandra+Levy%22 ) [7] => stdClass Object ( [name] => Chelsea [url] => http://search.twitter.com/search?q=Chelsea ) [8] => stdClass Object ( [name] => Mardi Gras [url] => http://search.twitter.com/search?q=%22Mardi+Gras%22 ) [9] => stdClass Object ( [name] => #followfriday [url] => http://search.twitter.com/search?q=%23followfriday ) ) )

    I would like to know how I can access the name and urls in this array. Any help will be appreciated.

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like any other array or object:
    PHP Code:
    $initialObject->trends[0]->url
    $initialObject
    ->trends[1]->url 
    or, for automating:
    PHP Code:
    foreach($initialObject->trends as $key=$obj){
      print 
    "name:{$obj->name} => {$obj->url}<br/>";


  3. #3
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rock and roll. thanks!


Tags for this Thread

Bookmarks

Posting Permissions

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