I have got the following array:
$raw = [
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'new'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'new'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'new'
],
];
I need to filter through this array, preferably using filter_array
to keep the code cleaner, I need to filter based on the path
property. So I would end up with:
$filtered = [
'used' => [
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'used'
]
],
'new' => [
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'new'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'new'
],
[
'prop1' => 'somevalue',
'prop2' => 'anothervalue',
'path' => 'new'
]
]
];