Hi, I am developing airplane tickets reservation system. Let's say I have an array of the roundtrip flights. Each flights has its price, outbound flight id and inbound flight id. For now let's assume there are only four roundtrip flights there: $roundtrips = array( array('price'=>'100', 'out'=>'10', 'in'=>'50'), array('price'=>'100', 'out'=>'10', 'in'=>'60'), array('price'=>'200', 'out'=>'20', 'in'=>'70'), array('price'=>'200', 'out'=>'30', 'in'=>'60'), ); PHP: I need to group this roundtrips by price to have output like this: <table border="1" width="300"> <tr> <td colspan="2"><h3>$100</h3></td> </tr> <tr><td colspan="2"><strong>Flights out</strong></td></tr> <tr><td width="270"> Flight 10</td><td width="30" align="center"><input type="radio" name="flight_out" value="10" /></td></tr> <tr><td colspan="2"><strong>Flights in</strong></td></tr> <tr><td width="270"> Flight 50</td><td width="30" align="center"><input type="radio" name="flight_in" value="50" /></td></tr> <tr><td width="270"> Flight 60</td><td width="30" align="center"><input type="radio" name="flight_in" value="60" /></td></tr> <tr><td colspan="2" align="right"><input type="submit" /></td></tr> <tr> <td colspan="2"><h3>$200</h3></td> </tr> <tr><td colspan="2"><strong>Flights out</strong></td></tr> <tr><td width="270"> Flight 20</td><td width="30" align="center"><input type="radio" name="flight_out" value="20" /></td></tr> <tr><td width="270"> Flight 30</td><td width="30" align="center"><input type="radio" name="flight_out" value="30" /></td></tr> <tr><td colspan="2"><strong>Flights in</strong></td></tr> <tr><td width="270"> Flight 60</td><td width="30" align="center"><input type="radio" name="flight_in" value="25" /></td></tr> <tr><td width="270"> Flight 70</td><td width="30" align="center"><input type="radio" name="flight_in" value="25" /></td></tr> <tr><td colspan="2" align="right"><input type="submit" /></td></tr> </table> Code (markup): And I can do it! However, look closely to the group of $200 price. The user can select the flowing combinations of outbound and inbound flights: 20/60, 20/70, 30/60, 30/70. But the combinations 20/60 and 30/70 are not valid, because there are no roundtrips with such 'out' and 'in' flights! So, in this case there should be 2 groups priced $200 so that the user couldn't select invalid combinations. How do I do this kind of grouping? Please help, I'll appreciate it.