时间:2021-07-01 10:21:17 帮助过:8人阅读
$array=array(
array('CKMC'=>'store1','GG1MC'=>'color1','GG2MC'=>'size1'),
array('CKMC'=>'store1','GG1MC'=>'color1','GG2MC'=>'size2'),
array('CKMC'=>'store1','GG1MC'=>'color2','GG2MC'=>'size1'),
array('CKMC'=>'store1','GG1MC'=>'color2','GG2MC'=>'size2'),
array('CKMC'=>'store2','GG1MC'=>'color1','GG2MC'=>'size1'),
array('CKMC'=>'store2','GG1MC'=>'color2','GG2MC'=>'size2'),
);
$array2=array();
foreach($array as $val)
{
if(array_key_exists($val['CKMC'],$array2))
{
if(array_key_exists($val['GG1MC'],$array2[$val['CKMC']]))
{
$array2[$val['CKMC']][$val['GG1MC']][]=$val;
}
else $array2[$val['CKMC']][$val['GG1MC']]=array($val);
}
else $array2[$val['CKMC']]=array($val['GG1MC']=>array($val));
}
echo '';';
print_r($array2);
echo '