将数组传递给视图(codeigniter)

时间:2017-09-08 01:49:56

标签: php arrays codeigniter web

array(2) {
  [0]=>
  object(stdClass)#21 (7) {
    ["id"]=>
    string(1) "1"
    ["title"]=>
    string(7) "cvxzcvd"
    ["con"]=>
    string(10) "gvsdvgsdfg"
    ["is_important"]=>
    string(1) "1"
    ["date"]=>
    string(3) "123"
    ["image"]=>
    string(2) "55"
    ["cat_id"]=>
    string(1) "1"
  }
  [1]=>
  object(stdClass)#22 (7) {
    ["id"]=>
    string(1) "2"
    ["title"]=>
    string(4) "fsdf"
    ["con"]=>
    string(9) "dfdsfvfds"
    ["is_important"]=>
    string(1) "1"
    ["date"]=>
    string(4) "5145"
    ["image"]=>
    string(7) "5454124"
    ["cat_id"]=>
    string(1) "2"
  }
}

我将此数组传递给视图

$this->load->view('home/index',$news_data);

但我想分开使用这些数据。 我的意思是,如果我想使用第二个标题 或第二个数据。 我怎样才能在视图中表达

感谢

2 个答案:

答案 0 :(得分:1)

你可以这样: -

$news_data[1]->title;
$news_data[1]->data;

答案 1 :(得分:1)

将数组存储到变量中,如

  

$ news_data ['arr'] = {};

,并在视图文件中通过$ arr访问它;

  

的print_r($ ARR);

相关问题