我从表中检索了一些数据。像
这样的表格数组
我想要数组是..
$subpro[HardDisk] = array (H1000 => 1200,H500 => 700);
$subpro[Ip] = array (4IP => 400 , 2IP => 200);
$subpro[Ram] = array (..);
$subpro[processor] = array (...);
php code ..
while($row=mysql_fetch_array($res))
{
if(sizeof($subpro[$row['category']]>0)
array_put_to_position($subpro[$row['category']],$row['rate'], 2,$row['name']);
else
$subpro[$row['category']]=array($row['name']=>$row['rate']);
}
答案 0 :(得分:2)
除非我误解了这个问题,否则答案很简单。
$subpro = array();
while($row = mysql_fetch_array($res)) {
$subpro[$row['category']][$row['name']] = $row['rate'];
}