我正在研究 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/