I've got a little problem getting an array sorted, and I'm not sure what the best method is.
Basically I've got an array with a bunch of keys like:
What I need to do is loop this array out, but sort them by the group their in, so I can arrange them in groups in my output. I.e. I need to have all "group1" looped out, then all "group2" and so on, but I need to be able to wrap content around each group in the HTML.
The tricky part is, I can't know exactly how many different groups I have, other than I can query the database, and get an array of which groups there are. So I really need to use an array of group names to sort this array by. Otherwise I could just use some "while..." in my foreaches, I suppose.
Does that make sense?
I'm not terribly strong with arrays, so while I can think of a few ways that seem logical, I'm not really sure what the best mechanism is in code.
L.
Basically I've got an array with a bunch of keys like:
Code:
array (size=12)
0 =>
object(stdClass)[336]
public 'name' => string 'imdg' (length=4)
public 'title' => string 'IMDG' (length=4)
public 'group' => string 'group1' (length=11)
1 =>
object(stdClass)[337]
public 'name' => string 'iata' (length=4)
public 'title' => string 'IATA' (length=4)
public 'group' => string 'group1' (length=11)
2 =>
object(stdClass)[338]
public 'name' => string 'rid' (length=3)
public 'title' => string 'RID' (length=3)
public 'group' => string 'group2' (length=11)
3 =>
object(stdClass)[339]
public 'name' => string 'reach' (length=5)
public 'title' => string 'REACH' (length=5)
public 'group' => string 'group2' (length=11)
What I need to do is loop this array out, but sort them by the group their in, so I can arrange them in groups in my output. I.e. I need to have all "group1" looped out, then all "group2" and so on, but I need to be able to wrap content around each group in the HTML.
The tricky part is, I can't know exactly how many different groups I have, other than I can query the database, and get an array of which groups there are. So I really need to use an array of group names to sort this array by. Otherwise I could just use some "while..." in my foreaches, I suppose.
Does that make sense?
I'm not terribly strong with arrays, so while I can think of a few ways that seem logical, I'm not really sure what the best mechanism is in code.
L.