iterating through a stdClass object in PHP

女生的网名这么多〃 提交于 2019-11-27 23:38:17
echo "<table>"

foreach ($object->values as $arr) {
    foreach ($arr as $obj) {
        $id   = $obj->group->id;
        $name = $obj->group->name;

        $html  = "<tr>";
        $html .=    "<td>Name : $name</td>";
        $html .=    "<td>Id   : $id</td>";
        $html .= "</tr>";
    }
}

echo "</table>";
gus
function objectToArray( $data ) 
{
    if ( is_object( $data ) ) 
        $d = get_object_vars( $data );
}

Convert the Object to array first like:

$results = objectToArray( $results );

and use

foreach( $results as result ){... ...}
foreach($res->values as $value) {
    print_r($value);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!