Tengo este array que armo con informacion de un xml
Código PHP:
// Reading all elements with tag name="game".
$cds = $doc->getElementsByTagName( "game" );
$data = array();
foreach ($cds as $cd)
{
$data[] = array('time' => TranslateDate($cd->getAttribute('time')),
'sport' => TranslateSport($cd->getElementsByTagName("sport")->item(0)->getAttribute('id')),
'league' => TranslateLeague($cd->getElementsByTagName("league")->item(0)->getAttribute('id')),
'away' => $cd->getElementsByTagName("away")->item(0)->getAttribute('abbr'),
'home' => $cd->getElementsByTagName("home")->item(0)->getAttribute('abbr'),
'aScores' => $cd->getElementsByTagName("away")->item(0)->getAttribute('score'),
'hScores' => $cd->getElementsByTagName("home")->item(0)->getAttribute('score'),
'status' => $cd->getElementsByTagName("status")->item(0)->getAttribute('value'));
}
Código PHP:
function groupArray($array,$groupkey)
{
if (count($array)>0)
{
$keys = array_keys($array[0]);
$removekey = array_search($groupkey, $keys); if ($removekey===false)
return array("Clave \"$groupkey\" no existe");
else
unset($keys[$removekey]);
$groupcriteria = array();
$return=array();
foreach($array as $value)
{
$item=null;
foreach ($keys as $key)
{
$item[$key] = $value[$key];
}
$busca = array_search($value[$groupkey], $groupcriteria);
if ($busca === false)
{
$groupcriteria[]=$value[$groupkey];
$return[]=array($groupkey=>$value[$groupkey],'groupeddata'=>array());
$busca=count($return)-1;
}
$return[$busca]['groupeddata'][]=$item;
}
return $return;
}
else
return array();
}
Cita:
Pero luego de agrupar quiero armar una tabla para cada juego que me retorne esta funcion, y no se como hacerlo, alguna ayuda por favor? Array
(
[0] => Array
(
[sport] => Football
[groupeddata] => Array
(
[0] => Array
(
[time] => TUE, 04:30 PM PST
[league] => College Football
[away] => OHI
[home] => BGN
[aScores] => 0
[hScores] => 21
[status] => 2nd Q
)
[1] => Array
(
[time] => TUE, 04:30 PM PST
[league] => College Football
[away] => BFU
[home] => TOL
[aScores] => 0
[hScores] => 21
[status] => 1st Q
)
)
)
[1] => Array
(
[sport] => Basketball
[groupeddata] => Array
(
[0] => Array
(
[time] => TUE, 04:35 PM PST
[league] => NBA
[away] => MIL
[home] => MIA
[aScores] => 27
[hScores] => 37
[status] => 2nd Q
)
[1] => Array
(
[time] => TUE, 05:35 PM PST
[league] => NBA
[away] => WAS
[home] => DAL
[aScores] =>
[hScores] =>
[status] =>
)
)
)
(
[0] => Array
(
[sport] => Football
[groupeddata] => Array
(
[0] => Array
(
[time] => TUE, 04:30 PM PST
[league] => College Football
[away] => OHI
[home] => BGN
[aScores] => 0
[hScores] => 21
[status] => 2nd Q
)
[1] => Array
(
[time] => TUE, 04:30 PM PST
[league] => College Football
[away] => BFU
[home] => TOL
[aScores] => 0
[hScores] => 21
[status] => 1st Q
)
)
)
[1] => Array
(
[sport] => Basketball
[groupeddata] => Array
(
[0] => Array
(
[time] => TUE, 04:35 PM PST
[league] => NBA
[away] => MIL
[home] => MIA
[aScores] => 27
[hScores] => 37
[status] => 2nd Q
)
[1] => Array
(
[time] => TUE, 05:35 PM PST
[league] => NBA
[away] => WAS
[home] => DAL
[aScores] =>
[hScores] =>
[status] =>
)
)
)