# Solutions for processing similar statistics in arrays (PHP)

Source: Internet
Author: User
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 );

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.