How to pass a multi dimensional array to a view in CodeIgniter

后端 未结 3 927
栀梦
栀梦 2021-01-24 00:36

this is really doing my nut in. I\'m passing a multidimensional array to a view like this:

$res = $this->deliciouslib->getRecentPosts();

3条回答
  •  感情败类
    2021-01-24 01:31

    Answer to your problem could be way of calling data from the array. Possible solutions:

    1. Get the data in an array with index.

      $data['**result**']=$this->deliciouslib->getRecentPosts();
      
    2. Now since the result of getRecentPosts() is an array of data, pass it to view

      $this->load->view('view_name', $data);
      
    3. If the result is an array, on View Page, access it via RIGHT INDEXING

      $result[0-9]['col_name'] e.g **var_dump($result[9]['Title']**);
      

      Otherwise if it is an array of objects,

      $result[0-9]=>col_name
      e.g **var_dump($result[9]=>title)**;

提交回复
热议问题