使用php mysql动态生成Highcharts中的分组类别

I m really stuck with this from 1 week, can anyone please help me in creating an array for creating an grouped categories in Highcharts from a database dynamically using php.Here is an example of a table

<pre><code>
   +-------+---------------+---------------------------+
   |BATCH  |   CATEGORY    |         GENDER            |
   +-------+---------------+---------------------------+
   | 2012  |    General    |   Male                    |
   | 2012  |    Test       |   Female                  |
   | 2013  |    General    |   Female                  |
   | 2013  |    Test       |   Male                    |
   +-------+---------------+---------------------------+
   </code></pre>

and i want this table to be structured like this

 <pre><code>
   Array ( [0] => 
            Array ( [name] => 2012 
                    [categories] => 
                    Array ( [0] => Array ( [name] => General 
                                           [categories] => Array ([0] => Male )) 
                            [1] => Array ( [name] => Test 
                                           [categories] => Array ([0] => Female )))) 
        [1] => 
            Array ( [name] => 2013 
                    [categories] => 
                    Array ( [0] => Array ( [name] => General 
                                           [categories] => Array ([0] => Female )) 
                            [1] => Array ( [name] => Test 
                                           [categories] => Array ([0] => Male )))) 
        )
   </code></pre>

please help me.......

Add in the grouped categories plugin for highcharts then create a javascript helper for the chart.