CodeIgniter Forums

Full Version: problem passing 2 level muldi-dimensional array to view
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]migdelmar[/eluser]
How come I can pass a 1 level multimensional array from controller to view, but when trying to pass a 2 level muldimensional array it fails?


Controller:
Code:
$multi[0]='banana';
  $multi[1]='apple';
  $multi[2]='grape';
  $multi[3][0]='yellow';
  $multi[3][1]='red';
  $multi[3][2]='green';
                $data['multi']=$multi;
                $this->load->view('myview', $data);


But a print_r($multi) in View shows this:

Quote: Array
(
[0] => banana
[1] => apple
[2] => orange
[3] => Array
)


See array with index 3? It only says "Array" inside the view, and same print_r inside controller displays all data correctly, it seems as if it's only possible to pass a 1 level multidimensional array to views, any ideas?

El Forum

[eluser]CodeIgniteMe[/eluser]
Try
Code:
var_dump($multi);

El Forum

[eluser]migdelmar[/eluser]
var_dump($multi) shows:

Quote:array(4) {
[0]=>
string(6) "banana"
[1]=>
string(5) "apple"
[2]=>
string(6) "grape"
[3]=>
string(5) "Array"
}

it seems as if the 2nd level of the multidimensional array is passing empty, same var_dump done in the controller before loading view shows the values correctly:

Quote:array(4) {
[0]=>
string(6) "banana"
[1]=>
string(5) "apple"
[2]=>
string(6) "grape"
[3]=>
array(3) {
[0]=>
string(5) "yellow"
[1]=>
string(5) "red"
[2]=>
string(9) "green"
}
}

is there an issue when passing 2 (or more) levels multidimensional arrays to views?

El Forum

[eluser]CodeIgniteMe[/eluser]
To verify your speculations, try this in your view
Code:
var_dump($multi[3]);

El Forum

[eluser]migdelmar[/eluser]
of course, it was my mistake, in order to perform some characters validation and standarization i was doing a loop to $data in controller before passing it to the view, and it was altering the arrays, sorry.

El Forum

[eluser]CodeIgniteMe[/eluser]
So, this issue is now solved.