我正在将数据转换为HighCharts [关闭]

This is the demo data.I have a foreach loop that I want to use to populate from the foreach loop into categories...

    array(
                'y' => 55.11,
                'color' => $colors[0],
                'drilldown' => array(
                    'name' => 'MSIE Versions',
                    'categories' => array('MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'),
                    'data' => array(10.85, 7.35, 33.06, 2.81),
                    'color' => $colors[0]
                )
            ),
    array(



                'y' => 55.11,
                'color' => $colors[0],
                'drilldown' => array(
                    'name' => 'MSIE Versions',
                    'categories' => array('MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'),
                    'data' => array(10.85, 7.35, 33.06, 2.81),
                    'color' => $colors[0]
                )
            ),

Essentially I want to be able to do this.. But I keep on coming with a syntax error why?

$chartData = array(
    foreach($schools as $school=>$value){
    array(
     'y' => 55.11,
                'color' => $colors[0],
                'drilldown' => array(
                    'name' => $value,
                    'categories' => array('MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'),
                    'data' => array(10.85, 7.35, 33.06, 2.81),
                    'color' => $colors[0]
                )
            )
}

);

You can't have a for each loop inside of an array assignment

You want to push them onto your array variable in side your foreach loop, ex:

foreach($schools as $school=>$value)
{
   $chartData[] = array(
            'y' => 55.11,
            'color' => $colors[0],
            'drilldown' => array(
                'name' => $value,
                'categories' => array('MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'),
                'data' => array(10.85, 7.35, 33.06, 2.81),
                'color' => $colors[0]
            )
        )
}