CodeIgniter Forums
how di I get view to echo iteger key arrays? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how di I get view to echo iteger key arrays? (/showthread.php?tid=7528)



how di I get view to echo iteger key arrays? - El Forum - 04-13-2008

[eluser]ICEcoffee[/eluser]
Hi all, I know this is probably simple, but I'm just getting to grips with PHP OOP/MVC.

I know and have successfully written code to pass associative array data to a view in Codeigniter ie:

Controller:
Code:
$data['name'] = "Harry";
$data['country'] = "UK";
$this->load->view('profile');

Then in the view file:
Code:
<?php echo $name; echo $country?>

but how do I echo an indexed array? where the array in the controller is:
Code:
$data = array(1=>, "Harry", "Country");

I want to produce a menu list, so I don't want to use pass an associated array?

Any help please?


how di I get view to echo iteger key arrays? - El Forum - 04-13-2008

[eluser]Seppo[/eluser]
Well... the expected way to do it is to store the indexed array in an associative array position
Code:
$data = array('data' => array(1, 2, 3));

However you can use, with the original data
Code:
echo ${1};



how di I get view to echo iteger key arrays? - El Forum - 04-13-2008

[eluser]ICEcoffee[/eluser]
Thanks seppo for the reply. Your first suggestion worked but:

Quote:However you can use, with the original data
echo ${1};

did not.


how di I get view to echo iteger key arrays? - El Forum - 04-13-2008

[eluser]Seppo[/eluser]
You are right. Sorry. It seems like extract does not extract the variables starting with integers.