如何将多维数组传递给$ this->数据?

时间:2013-09-23 07:15:27

标签: php sql codeigniter

Controller:

    $sid = $this->uri->segment(4);
    $serial = $this->contract_items->get_all_serial($id);
    $_items = array();
        foreach ($serial as $k => $v) {
            $oldserial =  $this->contract_items->get_childrens($sid);
            $_items[$v->contract_id] = array("children" => $oldserial);
        }
    $this->data['serial_items'] = $_items;
    $this->build_view("contracts/serial.php");

这是我在print_r()时的输出,我想要打印“FDO1643R26G” 我认为是“FDO1643R26G”。

Array ( [0] => Array ( [children] => Array ( [0] => stdClass Object ( [serial_num] => FDO1643R26G-XXX ) [1] => stdClass Object ( [serial_num] => FDO1643R26G-XXX-XXX ) ) ) )

1 个答案:

答案 0 :(得分:1)

您可以将关联数组中的数据传递给控制器​​的视图。在您的情况下,只需将数组分配给数组中的键,然后传递它:

$data['_items'] = $_items;

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

// in the view, you can access the array
// in $_items