3

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

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

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

2 回答 2

10

It shows an array of objects. There is only one object in it.

If:

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

Then:

echo $var[0]->id;
于 2013-08-19T22:58:48.303 回答
4

Access it like any other object.

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

And so on. If you have multiple objects inside the array, run it through a for loop to iterate the array.

For example:

for ($i=0;$i<sizeof($array);$i++) {
    echo $array[$i]->[object property];
}
于 2013-08-19T22:58:55.150 回答