如何从stdclass对象中获取数据


How to get data out of stdclass object?

我正在使用$this->db->get_where()从codeigniter中的数据库中获取数据。我使用print_r() 得到的返回跟随

它看起来像stdClass object的数组。任何能够访问此数组中值的人。

Array ( [0] =>    
    stdClass Object ( 
    [id] => 1 
    [password321] => qwerty
    [email123] => example@gmail.com 
    [username123] => xyz
    ) 
)

它显示了一个对象数组。里面只有一个物体。

如果:

$var =  $this->db->get_where();

然后:

echo $var[0]->id;

像访问其他对象一样访问它。

echo $array[0]->id //1
echo $array[0]->username123 //xyz

等等。如果数组中有多个对象,请通过for loop运行它来迭代数组。

例如:

for ($i=0;$i<sizeof($array);$i++) {
    echo $array[$i]->[object property];
}