时间:2021-07-01 10:21:17 帮助过:7人阅读
你这个少数啊,一共18组数字啊,最后就6组了?
也就是原始的最后两组数不要了?
for($i=0;$i3){ $newcity_arr[]= array($city_arr[$j][0],$city_arr[$j][1],$city_arr[$j][2]); $m = 0; $i = $n; } if($n == 3 and $n=$m){ $newcity_arr[]= array($city_arr[$j][0],$city_arr[$j][1],$city_arr[$j][2]); $m = 0; $i = $n; $n = 0; } } }
$ar = array( array('东北区', '哈尔滨', 'C', 76850.4600, 76850.4600, 76850.4600), array('东北区', '哈尔滨', 'C', 602267.1390, 602267.1390, 602267.1390), array('东北区', '哈尔滨', 'C', 55356.1110, 55356.1110, 55356.1110), array('东北区', '沈阳', 'B', 51855.8950, 51855.8950, 51855.8950), array('东北区', '沈阳', 'B', 385946.7430, 385946.7430, 385946.7430), array('东北区', '沈阳', 'B', 1588513.5266, 1588513.5266, 1588513.5266),);$n = 3; //锁定前 3 列$res = array();foreach($ar as $t) { $k = join('_', array_slice($t, 0, $n)); if(! isset($res[$k])) $res[$k] = array_slice($t, 0, $n); $res[$k][] = $t[$n];}$res = array_values($res);print_r($res);
Array( [0] => Array ( [0] => 东北区 [1] => 哈尔滨 [2] => C [3] => 76850.46 [4] => 602267.139 [5] => 55356.111 ) [1] => Array ( [0] => 东北区 [1] => 沈阳 [2] => B [3] => 51855.895 [4] => 385946.743 [5] => 1588513.5266 ))怎么输出,就不要我教了吧