I have an initial array:
$arr0 = array(
0 => array(
'a' => 1,
'b' => 1
)
1 => array(
'a' => 2,
'b' => 1
)
2 => array(
'a' => 3,
'b' => 2
)
3 => array(
'a' => 4,
'b' => 3
)
4 => array(
'a' => 5,
'b' => 3
)
);
I wish to divide it into separate arrays depending on its members' value of the field 'b', like so:
// $arr1 contains $arr0[0] and $arr0[1] because their value of 'b' is 1.
$arr1 = array(
0 => array(
'a' => 1,
'b' => 1
)
1 => array(
'a' => 2,
'b' => 1
)
);
// $arr2 contains $arr0[2] because its value of 'b' is 2.
$arr2 = array(
0 => array(
'a' => 3,
'b' => 2
)
);
// $arr3 contains $arr0[3] and $arr0[4] because their value of 'b' is 3.
$arr3 = array(
0 => array(
'a' => 4,
'b' => 3
)
1 => array(
'a' => 5,
'b' => 3
)
);
Now, the field 'b' can have any natural number for value, so it is not always three resulting arrays that I will need.
I have found a related question (and answers) here, but my problem is specific because I don't know in advance what original values 'b' has, and how many of different values there are.
Any ideas?
(edit: $arr3 was written as $arr1)