$param = array(
array (
'hykno' => '8B6D',
'mount' => '12',
'protypeid' => '1',
),
array (
'hykno' => 'CB',
'mount' => '56',
'protypeid' => '3',
),
array (
'hykno' => '8B6D',
'mount' => '34',
'protypeid' => '1',
),
array (
'hykno' => 'CB',
'mount' => '78',
'protypeid' => '3',
),
array (
'hykno' => 'CcB',
'mount' => '178',
'protypeid' => '4',
)
);
$u = array();
foreach ($param as $k => $v){
if (!in_array($v['protypeid'],$u)){
$u[] = $v['protypeid'];
}
}
$data = array();
foreach ($u as $uk => $uv)
{
foreach ($param as $pk => $pv)
{
if ($pv['protypeid'] == $uv)
{
$data[$uv]['hykno'] = $pv['hykno'];
$data[$uv]['mount'] []= $pv['mount'];
}
}
}
$data = array_values($data);
print_r($data);
结果是:
Array
(
[0] => Array
(
[hykno] => 8B6D
[mount] => Array
(
[0] => 12
[1] => 34
)
)
[1] => Array
(
[hykno] => CB
[mount] => Array
(
[0] => 56
[1] => 78
)
)
[2] => Array
(
[hykno] => CcB
[mount] => Array
(
[0] => 178
)
)
)
|