<?php
$datos = array();
while( $dato = $ejecuta->fetch_assoc() )
{
$datos[$dato['año']][] = $dato['meses'];
}
$months_list = array(
'enero', 'febrero', 'marzo', 'abril',
'mayo', 'junio', 'julio', 'agost',
'septiembre', 'octubre', 'noviembre', 'diciembre'
);
foreach( $datos as $year => $months )
{
uasort($months, 'sort_by_months');
echo $year . '<br>';
echo implode('<br>', $months);
echo '<hr>';
}
function sort_by_months($a, $b)
{
global $months_list;
$pos_a = array_search(strtolower($a), $months_list);
$pos_b = array_search(strtolower($b), $months_list);
if($pos_a == $pos_b)
return 0;
return $pos_a > $pos_b ? 1 : -1;
}
?>