时间:2021-07-01 10:21:17 帮助过:24人阅读
//第一步
$t1 = Array ( 0 => '南昌', 1 => '南昌', 2 => '赣州', 3 => '九江', 4 => '赣州', 5 => '九江');
$t2 = Array ( 0 => '优秀', 1 => '良好', 2 => '优秀', 3 => '良好', 4 => '优秀', 5 => '差等' );
$t = array_map(null, $t1, $t2);
print_r($t);
/* 得到
Array
(
[0] => Array
(
[0] => 南昌
[1] => 优秀
)
[1] => Array
(
[0] => 南昌
[1] => 良好
)
[2] => Array
(
[0] => 赣州
[1] => 优秀
)
[3] => Array
(
[0] => 九江
[1] => 良好
)
[4] => Array
(
[0] => 赣州
[1] => 优秀
)
[5] => Array
(
[0] => 九江
[1] => 差等
)
)
*/
//第二步
$r = array();
foreach($t as $v) {
$r[$v[0]][] = $v[1];
}
print_r($r);
/*得到
Array
(
[南昌] => Array
(
[0] => 优秀
[1] => 良好
)
[赣州] => Array
(
[0] => 优秀
[1] => 优秀
)
[九江] => Array
(
[0] => 良好
[1] => 差等
)
)
*/
//第三步
$r = array_map('array_count_values', $r);