标准类对象 foreach PHP [英] stdClass Object foreach PHP

查看:56
本文介绍了标准类对象 foreach PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在为我的问题寻找解决方案.Seams meny 和我有同样的问题,但我的问题仍然没有解决方案.

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.

我有一个 stdClass 对象,需要以 foreach 或类似的方式打印出来.

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

这是我用print_r($result)"得到的结果的一部分.

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
                                )

推荐答案

我不确切知道您想要什么,但是可以像数组一样轻松地通过对象进行 foreach.这个例子说明了这一点.

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;
}

这篇关于标准类对象 foreach PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆