I have an array like the below one
Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 2
[4] => 2
[5] => 3
[6] => 3
[7] => 3
[8] => 4
[9] => 4
[10] => 4
)
Is there any way to get a subset of this array using the values? So that, if need the subset of value 1, then it has to display
Array
(
[0] => 1
[1] => 1
[2] => 1
)
And if subset of 2 then
Array
(
[3] => 2
[4] => 2
)
And so on.. I need to preserve the index too.
I searched so many places. But didn't get an answer for this. I wish to avoid the multiple looping for this.