Find out the duplicate data and rewrite the function. how can this problem be solved?

Source: Internet
Author: User
Find out the duplicate data, function rewrite database this way, idwcwe1q32a03169b15b16q27q28g3 I want to get: into idwcwe1q3-1/23q3-2/24b1-1/25b1-2/26q2-1/27q2-2/find the duplicate data, function rewrite
In the database,
Id wc we
1 q 3
2 a 0
3 q 3
4 B 1
5 B 1
6 q 2
7 q 2
8g 3
I want to get:
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 to 1/2
7 q 2-2/2

------ Solution --------------------
After a few hours, I finally wrote it. I'll wipe it! At this time, I miss the strange program very much... I feel that the code is too disgusting.
The resulting cyclic array is assembled into an SQL update Database. If you create a function or something, you have to work on your own. if you don't understand the code, you can't ask me.

Array
(
[0] => 1 23 234
[1] => 2 24 235-1/2
[2] => 3 24 235-2/2
[3] = & gt; 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 );
------ Solution --------------------
Niu, how can this problem be solved in half. At least let's make a comment ..

The big version has not appeared for a long time. I miss it ..

Contact Us

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.