Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove duplicates in php arrays

2025-03-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to duplicate the php array". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to duplicate the php array.

1. Description

The arrray_unique function is used to remove duplicates from an array, and if more than two array values are the same, only the first value is retained.

The php5.2.9 version adds array_unique 's support for multi-dimensional groups, and the sort_flags parameter needs to be set to deal with multi-dimensional groups.

2. Grammar

Array_unique (array)

3. Parameters

Array

Sortingtype

4. Return value

Returns the filtered array.

5. Examples

One-dimensional array deduplicates:

Array_unique (array) $arr = array_unique ($classify)

Two-dimensional array deduplication:

Function assoc_unique ($arr, $key) {$tmp_arr = array (); foreach ($arr as $k = > $v) {if (in_array ($v [$key], $tmp_arr)) {unset ($arr [$k]);} else {$tmp_arr [] = $v [$key];} sort ($arr); return $arr } $aa = Array (Array (0 = > 1pint 1 = >'c'), Array (0 = > 2pint 1 = >'c'), Array (0 = > 3pint 1 = >'q'), Array (0 = > 1pint 1 = >'B'), Array (0 = > 2pint 1 = >'d'), Array (0 = > 3pint 1 = >'d'), Array (0 = > 4pm 1 = >'a'), Array (0 = > 6pm 1 = >'B'), Array (0 = > 6prima 1 = >'d')) # assoc_unique (array, de-health value); echo ""; print_r (assoc_unique ($aa,0))

When we use the array, we will find some duplicate elements, if we do not remove them, it will affect the subsequent use.

At this point, I believe you have a deeper understanding of "how to duplicate the php array". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report