Welcome Guest, Not a member yet? Register   Sign In
how di I get view to echo iteger key arrays?
#1

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

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB