Array ( [0] => Array ( [.id] => *0 [name] => default [as] => 64578 [router-id] => 0.0.0.0 [redistribute-connected] => false [redistribute-static] => false [redistribute-rip] => false [redistribute-ospf] => false [redistribute-other-bgp] => false [out-filter] => [client-to-client-reflection] => true [ignore-as-path-len] => false [routing-table] => [default] => true [disabled] => false ) )
如何将上面的数组循环并传递到Codeigniter中的视图中,请帮忙!
来自评论。
if ($this->mikrotikext->mikrotik_connect($ip,$username,$password,$port) == true) {
$this->routerosapi->write("/interface/eoip/print",false);
$READ = $this->routerosapi->read(false);
$data['eoip'] = $this->routerosapi->parseResponse($READ);
$this->load->view('mikrotik/interface_eoip', $data);
// $this->mikrotik_model->insert_pool($data);
}
答案 0 :(得分:0)
好吧,让我们暂时假设您将数组存储到名为$ myArray的变量中。然后,您可以执行以下操作:
$data["myArray"] = $myArray;
$this->load->view("path_to_your_view", $data);
第二个参数被发送到您的视图,但它会被展开,并且数组中的每个命名索引都会成为视图中自己的变量。因此,在视图中,您可以:
foreach($myArray as $key=>$value){
echo "<p>$key has a value of $value.</p>";
}
这就是它的全部。这很简单......