Solutions for handling homogeneous statistics in arrays (PHP)
$arrItem = Array (
Array (10000, ' China ', 1),
Array (10000, ' China ', 3),
Array (20000, ' us ', 2),
Array (30000, ' France ', 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 '
';
}
?
?
?
$arr = Array (
??? Array (' Countyid ' = 1, ' County ' = ' China ', ' Province ' and ' Hunan '),
??? Array (' Countyid ' = 1, ' County ' = ' China ', ' Province ' and ' Hunan '),
??? Array (' Countyid ' = 3, ' County ' = ' Japan ', ' province ', ' Nagoya '),
??? Array (' Countyid ' = 3, ' County ' = ' Japan ', ' Province ' and ' Tokyo '),
??? Array (' Countyid ' = 1, ' County ' = ' China ', ' Province ' and ' Beijing '),
??? Array (' Countyid ' = + 1, ' county ' = ' China ', ' province ' and ' Shandong '),
??? Array (' Countyid ' = + 1, ' county ' = ' China ', ' province ' and ' Shandong '),
??? Array (' Countyid ' = 2, ' county ' = ' us ', ' province ' + ' Ontario '),
??? Array (' Countyid ' = 2, ' county ' = ' us ', ' province ' + ' Ontario '),
??? Array (' Countyid ' = 3, ' County ' = ' Japan ', ' province ', ' Nagoya '),
);
$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);