Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/65644-solved-format-an-array/
Share on other sites

<?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>';
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.