找出重複資料來,函數改寫,該怎麼解決

來源:互聯網
上載者:User
找出重複資料來,函數改寫
資料庫裡這樣子,
id wc we
1 q 3
2 a 0
3 q 3
4 b 1
5 b 1
6 q 2
7 q 2
8 g 3
我要得到:變成
id wc we
1 q 3-1/2
3 q 3-2/2
4 b 1-1/2
5 b 1-2/2
6 q 2-1/2
7 q 2-2/2

------解決方案--------------------
蛋痛了數個小時終於寫好了,我擦!這個時候十分想念怪署黍啊...感覺代碼寫得太噁心了。
得到結果 迴圈數組拼裝成 SQL update 資料庫。搞成函數什麼的就自己勞動啦,代碼看不懂也莫問我,哢哢,太費腦子了.

Array
(
[0] => 1 23 234
[1] => 2 24 235-1/2
[2] => 3 24 235-2/2
[3] => 4 25 235-1/2
[4] => 5 25 235-2/2
[5] => 6 37 456-1/2
[6] => 7 37 456-2/2
)

PHP code
$array = array('1 23 234', '2 24 235', '3 24 235', '4 25 235', '5 25 235', '6 37 456', '7 37 456');$newArray = array();foreach ($array as $value) {    preg_match('/^[0-9]+\s([0-9]+\s[0-9]+$)/', $value, $mArray);    $newArray[] = $mArray[1];}$countArray = array_count_values($newArray);$fixArray = array();$i = 1;foreach ($newArray as $newkey => &$value) {    $newArrayKey = array();    if (array_key_exists($value, array_flip($newArray))) {        $newArrayKey = array_keys($newArray, $value);        if (count($newArrayKey) !== 1) {            $tmp = array_search($newkey, $newArrayKey);            $tmp = intval($tmp) + 1;            $fixArray[] = $i . ' ' . $value . '-' . $tmp . '/' . $countArray[$value];        } else {            $fixArray[] = $i . ' ' . $value;        }        $i++;    }}print_r($fixArray);
------解決方案--------------------
妞妞,哪有事情做到一半的到底。起碼也要注釋解釋一下吧。。

話說大版已好久沒現身了。挺想念的。。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.