De-duplicate elements in PHP arrays

Source: Internet
Author: User
: This article mainly introduces de-duplicated elements in PHP arrays. For more information about PHP tutorials, see. Remove repeated elements from the array:

1. pure natural raw methods from data structures:

Foreach ($ feerecord as $ value)
{
$ Fee_record_id = $ value ['feerecordid'];
If (! In_array ($ fee_record_id, $ fee_record_id_arr ))
{
$ Fee_record_id_arr [] = $ fee_record_id;
}
Else
{
Continue;
}
}

Return $ fee_record_id_arr;

2. PHP functions should be reasonably used, and the code implementation should be: one line

$ Fee_recorda_id_arr = array_values (array_unique (array_column ($ feerecord, 'feerecordid ')));

Three functions hints:

Array_values ($ arr) returns all values in the array and creates a digital index.
The array_unique ($ arr) array is de-duplicated, but the returned key values are not sequential.
Array_column ($ arr, $ key) retrieves all element values of key = $ key in a multi-dimensional array and forms an array of numbers.

The above introduces PHP array de-duplication elements, including the content, hope to be helpful to friends who are interested in PHP tutorials.

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.