如何从stdclass对象中获取数据?

时间:2013-08-19 22:53:22

标签: php codeigniter codeigniter-2 stdclass

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

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

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

2 个答案:

答案 0 :(得分:9)

它显示了一个对象数组。其中只有一个对象。

如果:

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

然后:

echo $var[0]->id;

答案 1 :(得分:4)

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

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

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

例如:

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