tags:

views:

72

answers:

1

Hi, Been searching for a solution for my problem. Seams meny has the same q as me, but still haven't got a solution for my problem.

I have a stdClass Object that needs to be printed out in a foreach or somlike like that.

Here is a cut of the result i get with a "print_r($result)".

stdClass Object
(
    [ServiceGroup] => Array
        (
            [0] => stdClass Object
                (
                    [Service] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [_] => 3D-modulering
                                    [count] => 71
                                )

                            [1] => stdClass Object
                                (
                                    [_] => CAD
                                    [count] => 81
                                )

                            [2] => stdClass Object
                                (
                                    [_] => Databasutveckling
                                    [count] => 118
                                )

                            [3] => stdClass Object
                                (
                                    [_] => Datainmatare
                                    [count] => 6
                                )

                            [4] => stdClass Object
                                (
                                    [_] => Driftsteknik
                                    [count] => 87
                                )

                            [5] => stdClass Object
                                (
                                    [_] => IT-konsult
                                    [count] => 39
                                )

                            [6] => stdClass Object
                                (
                                    [_] => IT-tekniker
                                    [count] => 223
                                )

                            [7] => stdClass Object
                                (
                                    [_] => Mjuk- och hårdvarutestning
                                    [count] => 150
                                )

                            [8] => stdClass Object
                                (
                                    [_] => Nätverksteknik
                                    [count] => 142
                                )

                            [9] => stdClass Object
                                (
                                    [_] => Produkttestare
                                    [count] => 171
                                )

                            [10] => stdClass Object
                                (
                                    [_] => Programmerare
                                    [count] => 146
                                )

                            [11] => stdClass Object
                                (
                                    [_] => Projektledning
                                    [count] => 156
                                )

                            [12] => stdClass Object
                                (
                                    [_] => Serviceteknik
                                    [count] => 157
                                )

                            [13] => stdClass Object
                                (
                                    [_] => Support
                                    [count] => 360
                                )

                            [14] => stdClass Object
                                (
                                    [_] => Systemadministration
                                    [count] => 145
                                )

                            [15] => stdClass Object
                                (
                                    [_] => Systemutveckling
                                    [count] => 110
                                )

                            [16] => stdClass Object
                                (
                                    [_] => Webbdesign
                                    [count] => 246
                                )

                            [17] => stdClass Object
                                (
                                    [_] => Webbutveckling
                                    [count] => 135
                                )

                            [18] => stdClass Object
                                (
                                    [_] => webmaster
                                    [count] => 103
                                )

                        )

                    [name] => Data/IT
                )

            [1] => stdClass Object
                (
                    [Service] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [_] => Affärsanalys
                                    [count] => 192
                                )

                            [1] => stdClass Object
                                (
                                    [_] => Aktuarie
                                    [count] => 20
                                )
A: 

I don't know exactly what you want, but can easily foreach through objects just like arrays. This example shows that.

foreach($result->ServiceGroup as $value){
    foreach($value->Service as $obj){
        echo $obj->_;
        echo $obj->count;
    }
    echo $value->name;
}
Rocket
Do you know away to sort the "Service" array, want the "_" with the highest count to display first.
Erik Larsson
No problem. I don't always think straight if I don't have my caffeine.
Rocket
Give me a sec, and I can make a sort.
Rocket
You are the best, thank you once more.
Erik Larsson
Try this on for size: http://paste-bin.com/view/cd31fc24
Rocket
Tried it, and got an error. http://paste-bin.com/view/974e886f
Erik Larsson
Warning: usort() [function.usort]: Invalid comparison function in /home/web77699/domains/wemake.se/public_html/projects/quickmatch/soap.php on line 75
Erik Larsson
Try `usort($value->Service, '_sort_service');` instead.
Rocket
Thanks a million !! It worked like a charm :)
Erik Larsson
You're welcome. :-D
Rocket
Found a wierd thing, http://paste-bin.com/view/6aa360a1. That comes out at the end of the result. As u can se there is no name like "count" and "_", how do u extract those values?
Erik Larsson
That's weird. I guess they'd just be Service->0 and Service->1.
Rocket
Ye that was my guess too, but get the error "Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in" when i use a nubmer. Tried like this to $one = '1'; Service->$one, but it dosent work either.
Erik Larsson
You might be able to just do Service[0], I'm not sure.
Rocket