CodeIgniter Forums

Full Version: how di I get view to echo iteger key arrays?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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?

El Forum

[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};

El Forum

[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.

El Forum

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