Welcome Guest, Not a member yet? Register   Sign In
Assigning new elements to an associated array witin a foreach
#1

[eluser]Tim Reynolds[/eluser]
I am having problems with assigning a new element to an array during a foreach loop.

While echoing the alias of the array position inside the foreach the new element seems to have been created and populated correctly. When you print the array outside the loop it does not contain the new fields. The code is part of a big method but the snippet is included,

Code:
$this->CI->template['navigation'] = $this->CI->page->getNav(0);
foreach($this->CI->template['navigation'] as $nav){
$subnav = $this->CI->page->getSubNav($nav['path']);
$nav['subnav'] = $subnav;
}

Is this the correct method of performing this operation? I can post more code/debug info if needed.

Thanks
#2

[eluser]überfuzz[/eluser]
Could you post the array before altering it and the array you're aiming for.
#3

[eluser]Krzemo[/eluser]
Code:
$nav['subnav'][] = $subnav;
???
#4

[eluser]mattpointblank[/eluser]
Cshamoh is right, you're just overwriting the same array index each time, so you should end up with just the final item in the $nav array in your subnav.




Theme © iAndrew 2016 - Forum software by © MyBB