gpt4 book ai didi

php - 想使用索引显示数据..?

转载 作者:行者123 更新时间:2023-11-28 03:30:17 25 4
gpt4 key购买 nike

我正在研究 codeigniter。我想显示从后端到 View 文件的数据。这是我的代码

$result = $obj->get_details();

if ($result[0])
{
for ($i=0; $i<count($result); $i++) {

echo $result [$i]['name'];
}
}

当我这样做时,出现错误“无法将 stdClass 类型的对象用作数组”。我想使用索引显示数据。例如,我只想在数组的第 5 个索引上显示名称。任何帮助都会很棒...谢谢!

最佳答案

试试看

for ($i=0; $i<count($result); $i++) {

echo $result[$i]->name;
}

因为 $result[$i] 是一个包含 name 值的对象

关于php - 想使用索引显示数据..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18314271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com