Group Array Based On Value
Posted: Sat Jan 23, 2016 3:51 pm
First, I know this should be easier than I have made it. I looked an tried other pieces of code from the net but can't seem to get my problem worked out. I have an xml that has been parsed into an array with the following:
So basically I have an array that list the start time, show title , and show description. Now I would like to parse that array grouping all show titles by start times so I end up with array something like where all shows for particular time fall into same array. Any help greatly appreciated
Code: Select all
foreach ($items as $load){
$contents[]= simplexml_load_file($load['guide']); //LOAD XML EACH CHANNEL
$control=[];
foreach ($contents as $content){
$control=array(
'start'=>$content->programme['start'],
'title'=>$content->programme->title,
'desc'=>$content->programme->desc,
);
}
}Code: Select all
Array
(
[20] => Array
(
[0] => Array
(
[start] => 20161221400
[title] => Show Title A
)
[1] => Array
(
[start] => 20161221400
[title] => Show Title B
)
[21] => Array
(
[0] => Array
(
[start] => 20161221800
[title] => Show Title A
)
[1] => Array
(
[start] => 20161221800
[title] => Show Title B
)
)