Hilly_2004 Posted September 9, 2007 Share Posted September 9, 2007 First off, let me apologise for asking such a newbie question... This is my code.... // Fetch RSS feed $rss = fetch_rss('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/eng_div_3/rss.xml'); if ($rss) { // Split the array to show first 10 $items = array_slice($rss->items, 0, 10); // Cycle through each item and echo foreach ($items as $item ) { echo '<li><a href="'.$item['link'].'">'.$item['title'].'</a> - '.$item['description'].'</li>'; } } else { echo '<h2>Error:</h2><p>'.magpie_error().'</p>'; } It's basically displaying information from an RSS feed on my page. However I want to display 2 pieces of that array at once, then in the next loop, get the next 2 arrays, and so on and so forth. Quote Link to comment https://forums.phpfreaks.com/topic/68533-newbie-displaying-2-array-items-at-once-then-loop-to-get-the-rest/ Share on other sites More sharing options...
recklessgeneral Posted September 9, 2007 Share Posted September 9, 2007 Hi, I would use a for loop instead of a foreach loop as it'll give you a bit more control in this situation. The for loop is based on a counter that'll get incremented by 2 each time round the loop. You can then access array elements $i and $i+1 for the two-at-a-time approach you were after. for ($i = 0; $i < 10; $i += 2) { $item1 = $items[$i]; $item2 = $items[$i + 1]; // Do something with $item1 and $item2 } cheers, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/68533-newbie-displaying-2-array-items-at-once-then-loop-to-get-the-rest/#findComment-344643 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.