日期:2014-05-17 浏览次数:20522 次
$arrItem = array(
Array (10000,'中国',1),
Array (10000,'中国',3),
Array (20000,'美国',2),
Array (30000,'法国',5)
);
$arr = array();
foreach($arrItem as $v){
??? $arr[$v[0]] = isset($arr[$v[0]]) ? $arr[$v[0]] + $v[2] : $v[2];
??? print_r($arr);
??? echo '<br />';
}
?
?
?
$arr = array(
??? array('countyid' => 1, 'county' => '中国', 'province' => '湖南'),
??? array('countyid' => 1, 'county' => '中国', 'province' => '湖南'),
??? array('countyid' => 3, 'county' => '日本', 'province' => '名古屋'),
??? array('countyid' => 3, 'county' => '日本', 'province' => '东京'),
??? array('countyid' => 1, 'county' => '中国', 'province' => '北京'),
??? array('countyid' => 1, 'county' => '中国', 'province' => '山东'),
??? array('countyid' => 1, 'county' => '中国', 'province' => '山东'),
??? array('countyid' => 2, 'county' => '美国', 'province' => '安大略'),
??? array('countyid' => 2, 'county' => '美国', 'province' => '安大略'),
??? array('countyid' => 3, 'county' => '日本', 'province' => '名古屋'),
);
$countyGroupCount = array();
$countyProvinceGroupCount = array();
foreach ($arr as $row) {
??? $countyKey = $row['county'];
??? $countyProvinceKey = $row['county'] . '-' . $row['province'];
??? if (!isset($countyGroupCount[$countyKey])) {
??????? $countyGroupCount[$countyKey] = 1;
??? } else {
??????? $countyGroupCount[$countyKey] += 1;
??? }
??? if (!isset($countyProvinceGroupCount[$countyProvinceKey])) {
??????? $countyProvinceGroupCount[$countyProvinceKey] = 1;
??? } else {
??????? $countyProvinceGroupCount[$countyProvinceKey] += 1;
??? }
}
print_r($countyGroupCount);
print_r($countyProvinceGroupCount);