Two php methods to remove duplicate items of two-dimensional arrays, two php methods to remove two-dimensional arrays _ PHP Tutorial

Source: Internet
Author: User
Two php methods are used to remove duplicate items of two-dimensional arrays, and two php methods are used to remove two-dimensional arrays. Two php methods to remove duplicate items from two-dimensional arrays, and two php methods to remove duplicate values from two-dimensional arrays. the code is as follows: Method 1: two-dimensional array remove two php methods to remove two-dimensional array duplication, two php methods to remove two-dimensional array

Php removes the duplicate values of two-dimensional arrays. the code is as follows:
Method 1:

// Remove the duplicate value from the two-dimensional array function array_unique_fb ($ array2D) {foreach ($ array2D as $ v) {$ v = join (',', $ v ); // reduce the dimension. you can also use implode to convert a one-dimensional array to a comma-connected string $ temp [] = $ v ;}$ temp = array_unique ($ temp ); // remove the duplicate string, that is, the repeated one-dimensional array foreach ($ temp as $ k => $ v) {$ temp [$ k] = explode (',', $ v); // re-assemble the split array} return $ temp ;}

Method 2:

// Remove duplicate values from the two-dimensional array and retain the key value function array_unique_fb ($ array2D) {foreach ($ array2D as $ k = >$ v) {$ v = join (', ', $ v); // dimension reduction. you can also use implode to convert a one-dimensional array to a comma-connected string $ temp [$ k] = $ v ;} $ temp = array_unique ($ temp); // remove the duplicate string, that is, the repeated one-dimensional array foreach ($ temp as $ k => $ v) {$ array = explode (',', $ v ); // re-assemble the split array // modify the following indexes as needed. $ temp2 [$ k] ['id'] = $ array [0]; $ temp2 [$ k] ['title'] = $ array [1]; $ temp2 [$ k] ['keyword'] = $ array [2]; $ temp2 [$ k] ['content'] = $ array [3];} return $ temp2 ;}

The two php methods to remove duplicate items of two-dimensional arrays have their own advantages and disadvantages. you can choose one based on your situation.

The method for removing duplicate values of two-dimensional arrays in php is summarized as follows: Method 1: // remove two-dimensional arrays...

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.