[eluser]xjermx[/eluser]
Sorry for the newbie question-
I have the following code:
Code: $data = array(
"ID" => array(0,1,2,3,4,5),
"First" => array('f1'=>'Bob','f2'=>'Joe','f3'=>'Mike','f4'=>'Nancy','f5'=>'Harry','f6'=>'Jane'),
"Last" => array('l1'=>'Barker','l2'=>'Jackson','l3'=>'Moran','l4'=>'Nibbler','l5'=>'Houdini','l6'=>'Jumper');
);
$this->load->view('myview', $data);
If I've understood correctly, the load->view "extracts" the data, and my multidimensional array becomes basically multiple (one dimension) arrays over in my view. Am I correct?
My second question then is if there's another or better way to move a multidimensional array from my controller/model to a view so that I can spit out its contents.
Thanks!
[eluser]steelaz[/eluser]
With above setup, you will have access to 3 variables in your view:
Code: $ID = array(0,1,2,3,4,5);
$First = array('f1'=>'Bob','f2'=>'Joe','f3'=>'Mike','f4'=>'Nancy','f5'=>'Harry','f6'=>'Jane');
$Last = array('l1'=>'Barker','l2'=>'Jackson','l3'=>'Moran','l4'=>'Nibbler','l5'=>'Houdini','l6'=>'Jumper');
To send it as multidimensional array:
Code: $multi = array(
"ID" => array(0,1,2,3,4,5),
"First" => array('f1'=>'Bob','f2'=>'Joe','f3'=>'Mike','f4'=>'Nancy','f5'=>'Harry','f6'=>'Jane'),
"Last" => array('l1'=>'Barker','l2'=>'Jackson','l3'=>'Moran','l4'=>'Nibbler','l5'=>'Houdini','l6'=>'Jumper');
);
$data['multi'] = $multi;
$this->load->view('myview', $data);
And access it in view like this:
Code: // Will echo "Bob"
echo $multi['First']['f1'];
[eluser]xjermx[/eluser]
Fantastic, thanks!
|