prova detta while($row = mysql_fetch_array($result)) { $arr[$row['group']][] = array('val' => $row['value']); }