PHP Array de-weight

Source: Internet
Author: User

A one-dimensional array can be array_unique directly using the () function, or use two times array_flip () to go heavy, but the multidimensional array will need to write its own

The previous few days a simple Deduplication method was written for several fields in a two-dimensional array that require special inability to duplicate

    Private functionUnique_arr ($data)    {        $temp=Array(); foreach($data  as $key=$datum) {            $k=$datum[' site ']. ", {$datum[' No ']},{$datum[' Code ']},{$datum[' Type ']} ";//Dimensionality , will need to join the unique field stitching into a string to make the keys of the array            $temp[$k] =$datum; }        $temp _final= []; foreach($temp  as $v){            $temp _final[] =$v;//re-assemble the disassembled array        }        return $temp _final; }

This is because the specified fields need to be federated unique, so when the same time occurs, because of the nature of the array, when the key name already exists, the key value will be replaced by the last value corresponding to this key name, so when there is duplicate content, will replace the previous data, only the last one to retain the data, Thus achieving a de-weight effect

PHP Array de-weight

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.