How to calculate array deduplication is difficult-php Tutorial

Source: Internet
Author: User
Array deduplication is difficult to calculate. there is an array that needs to be deduplicated. the format of the array is discussed online.


Reply to discussion (solution)

Paste the sample array output by var_export. the basis for not discussing is not discussed.

In fact, it is very simple. you only need to press the cluster key to cluster.

Paste the sample array output by var_export. the basis for not discussing is not discussed.

In fact, it is very simple. you only need to press the cluster key to cluster.

This is the current array.


Expected format:


Could you tell me how to format it like this?

Why? Do I have to type them one by one?

What are the requirements? If it is simply implemented, can it be a loop?

 
 Array ('id' => 0, 'Send _ mobile' => '000000', 'c _ content' => 'Hot weather and heat tolerance '), 1 => array ('id' => 1, 'Send _ mobile' => '000000', 'c _ content' => 'Hot weather, heat proof '), 2 => array ('id' => 2, 'Send _ mobile' => '000000', 'c _ content' => 'Hot weather, heat proof '), 3 => array ('id' => 3, 'Send _ mobile' => '000000', 'c _ content' => 'weather heat ')); $ arrb = array (); foreach ($ arra as $ v) {$ B = $ v ['c _ content']; if (isset ($ arrb [$ B]) $ arrb [$ B] ['send _ mobile'] . = ','. $ V ['send _ mobile']; $ arrb [$ B] = isset ($ arrb [$ B])? $ Arrb [$ B]: $ v ;}$ arrb = array_values ($ arrb); print_r ($ arrb);?>


Let's see if you use c_id for differentiation. Then, use cid for key directly. $ arr [$ cid] [] = $ val

I suggest you use Chinese as an array key.

Foreach ($ arra as $ k =>v v) {$ res [$ v [c_content] = $ v ;}
One sentence OK

Create an array B and traverse original array a. if c_content in the traversal item does not appear in column B as the key name, insert B [c_content]; otherwise, add send_mobile to the traversal, and sort the entire ReKey value of array B.

 
 Array ('id' => 0, 'Send _ mobile' => '000000', 'c _ content' => 'Hot weather and heat tolerance '), 1 => array ('id' => 1, 'Send _ mobile' => '000000', 'c _ content' => 'Hot weather, heat proof '), 2 => array ('id' => 2, 'Send _ mobile' => '000000', 'c _ content' => 'Hot weather, heat proof '), 3 => array ('id' => 3, 'Send _ mobile' => '000000', 'c _ content' => 'weather heat ')); $ arrb = array (); foreach ($ arra as $ v) {$ B = $ v ['c _ content']; if (isset ($ arrb [$ B]) $ arrb [$ B] ['send _ mobile'] . = ','. $ V ['send _ mobile']; $ arrb [$ B] = isset ($ arrb [$ B])? $ Arrb [$ B]: $ v ;}$ arrb = array_values ($ arrb); print_r ($ arrb);?>





Thank you for solving this problem.

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.