I have one large array and I want to group this into other arrays based on a common ID so that I can use array_splice to get only the first and last occurrence of that ID.
array(
[0] => array(id => 34, name = "walter"),
[1] => array(id => 25, name = "walter jr"),
[2] => array(id => 34, name = "saul"),
[3] => array(id => 25, name = "jesse"),
[4] => array(id => 25, name = "todd")
)
What I want to end up with is something like this.
array(
[0] => array(
id => 34, name = "walter",
id => 34, name = "saul"
),
[1] => array(
id => 25, name = "walter jr",
id => 25, name = "jesse",
id => 25, name = "todd"
)
)
I'm having a really hard time trying to wrap my head around how to accomplish this and have searched all over. I've found some solutions using array_unique and array_diff but i'm never able to get the result i'm looking for.