php array將橫排變成豎排的實現方法

來源:互聯網
上載者:User
東北區 哈爾濱 C 76850.4600 76850.4600 76850.4600
東北區 哈爾濱 C 602267.1390 602267.1390 602267.1390
東北區 哈爾濱 C 55356.1110 55356.1110 55356.1110
東北區 瀋陽 B 51855.8950 51855.8950 51855.8950
東北區 瀋陽 B 385946.7430 385946.7430 385946.7430
東北區 瀋陽 B 1588513.5266 1588513.5266 1588513.5266
相同城市的不同的三個數合并到同一行去,這個php array 咋寫啊
變成如下形式:
東北區 哈爾濱 C 76850.4600 602267.1390 55356.1110
東北區 瀋陽 B 51855.8950 385946.7430 1588513.5266


有什麼思路嗎大家


回複討論(解決方案)

你這個少數啊,一共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        ))
怎麼輸出,就不要我教了吧
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.