terrid25 Posted January 26, 2011 Share Posted January 26, 2011 Hi I have an array of items that I am currently displaying a foreach loop What I'm looking to do, is add a string, to all of items, a part from the last 4: foreach ($pager->getResults() as $items => $item) { echo $item->getName(); //need to add a string to this for the all but the last 4 } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225736-foreach-loop-adding-a-string-to-all-items-apart-from-the-last-4/ Share on other sites More sharing options...
Pikachu2000 Posted January 26, 2011 Share Posted January 26, 2011 Count the array elements, then while the loop runs decrement the count. If the remaining count is higher than 4, concatenate the string, else don't. Quote Link to comment https://forums.phpfreaks.com/topic/225736-foreach-loop-adding-a-string-to-all-items-apart-from-the-last-4/#findComment-1165474 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.