I have an array in PHP that looks like this... it's sorted in ascending order by the 'generation' value
Array
(
[0] => Array
(
[userID] => 1
[userName] => Grandfather
[generation] => 1
)
[1] => Array
(
[userID] => 2
[userName] => Father
[generation] => 2
)
[2] => Array
(
[userID] => 3
[userName] => Son
[generation] => 3
)
[3] => Array
(
[userID] => 4
[userName] => Daughter
[generation] => 3
)
)
I want to create an HTML table that looks like this...
One row for each generation, with each member of the generation seperated by a comma.
I've tried multiple versions of 'foreach' and 'while' solutions but haven't been able to get it right.
This is the closest I have come to success...
echo '<table>';
$x = 1;
foreach ($usersArray as $subArray){
if($subArray['generation'] == $x){
echo '<tr>';
echo '<td>'.$subArray['userName'].'</td>';
echo '</tr>';
}
$x++;
}
echo '</table>';
This code however will only print the first member of each generation giving a table of...
Any help is appreciated.

