I’ve got the below $test array sorted by ‘date‘ and ‘site‘.
$test = array (
0 => array (
'id' => '45',
'rating' => 'p1',
'site' => 'Heavener SW',
'time' => '11-03-2012 Sat 10:00:00',
),
1 => array (
'id' => '45',
'rating' => 'h3',
'site' => 'Heavener SW',
'time' => '11-03-2012 Sat 10:00:00',
),
2 => array (
'id' => '45',
'rating' => 'h4',
'site' => 'Heavener SW',
'time' => '11-03-2012 Sat 16:00:00',
),
3 => array (
'id' => '110',
'rating' => 'p3',
'site' => 'Red Oak',
'time' => '11-03-2012 Sat 16:00:00',
),
4 => array (
'id' => '110',
'rating' => 'h3',
'site' => 'Red Oak',
'time' => '11-03-2012 Sat 16:00:00',
),
5 => array (
'id' => '32',
'rating' => 'p2',
'site' => 'Panopoint',
'time' => '11-04-2012 Sun 10:00:00',
)
);
I’ve gone nuts trying to combine ‘ratings’ for each ‘site’-‘time’ combination.
$result = array (
0 => array (
'id' => '45',
'rating' => 'p1, h3',
'site' => 'Heavener SW',
'time' => '11-03-2012 Sat 10:00:00',
),
2 => array (
'id' => '45',
'rating' => 'h4',
'site' => 'Heavener SW',
'time' => '11-03-2012 Sat 16:00:00',
),
3 => array (
'id' => '110',
'rating' => 'p3, h3',
'site' => 'Red Oak',
'time' => '11-03-2012 Sat 16:00:00',
),
5 => array (
'id' => '32',
'rating' => 'p2',
'site' => 'Panopoint',
'time' => '11-04-2012 Sun 10:00:00',
)
);
There’s no limits on the number of ‘ratings’ a site can have or how many ‘sites’ or ‘time’ there are (within reason).
Preserving the index in the $result is optional (ie. not necessary).
I found this similar post(and others) but I don’t understand how to implement.
Getting all the related ones based on value
I’ve tried so many differnt ways my head is spinning, any help is greatly appreciated!
You can simply use
array_reduceOutput
See Live Demo