|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
|
#2
|
||||
|
||||
|
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:
Then you'd do an array_diff between $o and your second array listed below. |
|
#3
|
||||
|
||||
|
Great! It works!
- Mojoman |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > how do I convert a stdClass Object into an array? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|