General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 8th, 2003, 12:24 PM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 12
how do I convert a stdClass Object into an array?

I am trying to use array_diff() using two arrays. I suspect that one is an associative array and the other an object array:

(Object Array?)
Array
(
[0] => stdClass Object
(
[folder] => Columbia_215
)

[1] => stdClass Object
(
[folder] => Wormwood_21-405
)

)

- and -

(Associative Array)
Array
(
[0] => Wormwood_21-406
[1] => 21Wormwood405
[2] => Columbia_215
[3] => Wormwood_21-405
[4] => wormwood_34-405-a
)

When I use array_diff() with these two I get the term "object" as a result. This leads me to believe that I need to convert the object array into an associative array.

How do I convert the object array into an associative array? I am a self taught novice with no programming experience (php is my first experience with programming) so please keep any answers simple!

TIA!
__________________
$mybrain = "mush";
-------------------------------------------
http://www.loftsboston.com
http://www.gregdawsondesign.com

Reply With Quote
  #2  
Old October 8th, 2003, 01:01 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via ICQ to dhouston
Actually, the second isn't what you'd typically call an associative array, as it doesn't have text indices. At any rate, it does appear that you've got an array of objects and an array of strings. What you'll probably need to do is to iterate through the array of objects, and push onto a new array the result of a method that returns the folder attribute of the object. Then you can compare this array to the second array you list.

So you'd write a function in the stdClass that returns $this->folder. Then you'd do something like the following:

PHP Code:
 $o=array();
foreach(
$objectArray as $obj){
    
array_push($o,$obj->get_folder());



Then you'd do an array_diff between $o and your second array listed below.

Reply With Quote
  #3  
Old October 8th, 2003, 10:23 PM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 12
Great! It works!

- Mojoman

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > how do I convert a stdClass Object into an array?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap