How to format within a foreach loop

I´m a newbie on php so excuse me for my nescience.

I have this working code…

[php]<?php foreach ( $bandinfo as $infoband ) : ?>

<?php echo $infoband['band']," "; ?><?php echo $infoband['lineup']," "; ?><?php echo $infoband['year']; ?>
<?php endforeach; ?>[/php]

And it gives me this result

Band1 lineup1 year1
Band1 lineup2 year2
Band1 lineup3 year3
Band2 lineup1 year1
Band2 lineup2 year2
Band2 lineup3 year3

But I wont this format

Band1
lineup1 year1
lineup2 year2
lineup3 year3

Band2
lineup1 year1
lineup2 year2
lineup3 year3

How do I do that?

[php]
foreach($bandinfo as $infoband) {
if($prev_band == $infoband[‘band’]) {
echo $infoband[‘band’];
$prev_band = $infoband[‘band’];
}
echo $infoband[‘lineup’]." “.$infoband[‘year’].”
";
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service