我将数据库查询的结果存储在变量$ lists
中print_r给出了以下输出:
DB Object
(
[_pdo:DB:private] => PDO Object
(
)
[_query:DB:private] => PDOStatement Object
(
[queryString] => SELECT * FROM lists
)
[_error:DB:private] =>
[_results:DB:private] => Array
(
[0] => stdClass Object
(
[id] => 10
[list_name] => Farmer
)
[1] => stdClass Object
(
[id] => 11
[list_name] => Gardener
)
[2] => stdClass Object
(
[id] => 12
[list_name] => Plumber
)
)
[_count:DB:private] => 3
)
通过使用for循环,我可以按如下方式访问list_names:
foreach ($lists->results() as $person) {
echo $person->list_name;
}
这给了我: 农民 园丁 管道工
我想要做的是直接访问list_name但我根本无法理解如何。