Solutions for processing similar statistics in arrays (PHP) $ arrItemarray (Array (10000, China, 1), Array (10000, China, 3), Array (20000, United States, 2), Array (30000, France, 5); $ arrarray (); foreach ($ arrItemas $ v ){??? $ Arr [$ v [solutions for processing similar statistics in arrays (PHP)
$ ArrItem = array (
Array (10000, 'China', 1 ),
Array (10000, 'China', 3 ),
Array (20000, 'u.s. ', 2 ),
Array (30000, 'French ', 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' => 'hunan '),
??? Array ('countyid' => 1, 'county '=> 'China', 'Province' => 'hunan '),
??? Array ('countyid' => 3, 'county '=> 'Japan', 'Province '=> 'nagoya '),
??? Array ('countyid' => 3, 'county '=> 'Japan', 'Province '=> 'Tokyo '),
??? Array ('countyid' => 1, 'county '=> 'China', 'Province' => 'Beijing '),
??? Array ('countyid' => 1, 'county '=> 'China', 'Province' => 'Shandong '),
??? Array ('countyid' => 1, 'county '=> 'China', 'Province' => 'Shandong '),
??? Array ('countyid' => 2, 'county '=> 'u.s.', 'Province '=> 'onon '),
??? Array ('countyid' => 2, 'county '=> 'u.s.', 'Province '=> 'onon '),
??? 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 );