gpt4 book ai didi

php - 数组 - foreach 带来 -> fatal error : Cannot use object of type

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:53:31 27 4
gpt4 key购买 nike

所以,我对这个阵列很生气,第 2 天让我感到疼痛 *....

我正在开发面向对象的 PHP 脚本。

我得到一个数组:

Array ( [0] => Project Object ( [project_id] => 1 [title] => Some Name [date] => 2011-10-20 [place] => Some City [customer] => 1 [proj_budget] => [manager] => 1 [team] => 1 [currency] => 1 ) )

当我尝试这样做时:

<?php
$project = new Project();
$projects = $project->findAll();
print_r($projects);
foreach ($projects as $temptwo) {
echo $temptwo['title'].", \n";
}
?>

我明白了:

Fatal error: Cannot use object of type Project as array

为什么在世界上?它想从我这里得到什么?

最佳答案

您将项目作为数组访问

echo $temptwo['title'].", \n";

你可能想访问他们的属性

echo $temptwo->title.", \n";

关于php - 数组 - foreach 带来 -> fatal error : Cannot use object of type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7463954/

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