5

我在codeigniter中有以下输出?

Array
(
    [0] => stdClass Object
        (
            [id] => 8
            [book_category] => C Program
            [book_id] => 2
            [book_name] => C Language
            [book_category_id] => 8
            [book_in_stock] => 5
        )

    [1] => stdClass Object
        (
            [id] => 8
            [book_category] => C Program
            [book_id] => 1
            [book_name] => C++
            [book_category_id] => 8
            [book_in_stock] => 10
        )

    [2] => stdClass Object
        (
            [id] => 9
            [book_category] => English
            [book_id] => 3
            [book_name] => Comp Eng
            [book_category_id] => 9
            [book_in_stock] => 5
        )

    [3] => stdClass Object
        (
            [id] => 9
            [book_category] => English
            [book_id] => 4
            [book_name] => Eng English
            [book_category_id] => 9
            [book_in_stock] => 5
        )

)

所以我需要从上面的数组中获取值而不需要 foreach 的调试目的?

4

4 回答 4

8

尝试这个:

echo $array[0]->id;
echo $array[0]->book_category;
于 2012-06-28T08:19:41.087 回答
4

这将轻松获得价值

foreach($array as $key =>$value){ 
  echo $array[$key]->id;
  echo $array[$key]->book_category;
}
于 2013-07-13T20:37:30.817 回答
1

数组永远不会得到回显,用 print_r() 试试这个;

于 2013-08-09T10:47:42.473 回答
1

如果您想轻松查看数组的内容,则var_dump是您的最佳选择。

于 2012-06-28T14:27:58.923 回答