I have an array:
[['a', 1], ['b', 1], ['c',2], ['d',2]]
How can I group the subarrays based on the second column value like this:
[[['a', 1], ['b', 1]], [['c',2], ['d',2]]]
I have an idea to solve this with a foreach, but it may have a way with the built-in functions?
Sketch with foreach:
$in = [['a', 1], ['b', 1], ['c',2], ['d',2]];
$out = [];
foreach($in as $i) {
$out[$i[1]][] = $i;
}