php_dave Posted August 19, 2007 Share Posted August 19, 2007 Hi all, Im struggling with something probably really easy!! but just cant work it out! I have an array that is populated like so 1, 1, 2007-08-16, 1, 2, 1 2, 1, 2007-08-16, 2, 2, 1 3, 1, 2007-08-16, 5, 6, 1 4, 2, 2007-08-16, 1, 3, 1 5, 2, 2007-08-16, 1, 5, 6 im trying cycle through this array and use the 2nd value as a group or header like below 1: 1, 2, 1 2, 2, 1 5, 6, 1 2: 1, 3, 1 1, 5, 6 I cant get close - any ideas? Cheers Dave Quote Link to comment https://forums.phpfreaks.com/topic/65644-solved-format-an-array/ Share on other sites More sharing options...
Psycho Posted August 19, 2007 Share Posted August 19, 2007 <?php $currentHeader = ''; foreach ($array as $valueArray) { if ($currentHeader != $valueArray[1]) { echo '<b>' . $valueArray[1] . ':</b><br>'; $currentHeader = $valueArray[1]; } echo $valueArray[3] . ', ' . $valueArray[4] .', '. $valueArray[5] . '<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65644-solved-format-an-array/#findComment-327873 Share on other sites More sharing options...
php_dave Posted August 19, 2007 Author Share Posted August 19, 2007 I knew it would be easy - I always overthink stuff!! Cheers mate Quote Link to comment https://forums.phpfreaks.com/topic/65644-solved-format-an-array/#findComment-327953 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.