1

已传递的第一个数组,其值可以输出,而第二个数组产生错误.. 我们尝试在两个数组上使用 print_r 命令,它包含一个值

这是我们尝试过的

控制器

$project['project'] = (call model with return value);
$amenity['amenity'] = (call model with return value);

$data['project'] = $project;
$data['amenity'] = $amenity;

$this->load->view('view.php', $data);

看法

//this code works
foreach($project is $i){
     echo 'title: '.$i[0]->title;
}
//this code produce error, undefined object $amenity
foreach($amenity is $j){
     echo 'amenity: '.$j[0]->amenity;
}
4

1 回答 1

1

这样做:

$data['project'] = (call model with return value);
$data['amenity'] = (call model with return value);

$this->load->view('view.php', $data);

看法:

// foreach for $project
foreach($project as $i){
     echo 'title: '.$i['title'];
}
// foreach for $amenity
foreach($amenity as $j){
     echo 'amenity: '.$j['amenity'];
}
于 2013-07-31T22:41:18.427 回答