Array Looping |
[eluser]georgerobbo[/eluser]
Code: <div id="sidebar"> Code: $data['sideitem']['0'] = array('Lorem Ipsum', 'Vivamus Lobortis', 'Donec Pharetra'); I currently have a loop going where each new value from an array should start a new <div class="sideitem">. That works, however the values from the array $data['sideitem']['1'] are not being divided into a seperate container, but instead all of them are being placed in every container. What is the work around? A live example http://georgerobbo.dyndns.org
[eluser]kgill[/eluser]
They're in every container because you put them there. Look at your logic and your data - you're looping through the first array and each pass you make through it you do a complete loop of the second array. Lose the 2nd for loop and alter your 1st loop to get both the key and the value. Use the key to fetch the corresponding text $sideitem['1'][$key], either that or alter your array structure so that each title & text is together like this: Code: $sideitem[0] = array('title' => 'lorem ipsum', 'text'=>'blah blah blah');
[eluser]georgerobbo[/eluser]
Great! Thanks for the help, works perfectly. Now my next mountain is to get the information from those arrays to originated from a database. |
Welcome Guest, Not a member yet? Register Sign In |