PHP array go to heavy elements

Source: Internet
Author: User
To remove duplicate elements from an 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;

Reasonable use of 2.PHP functions, code implementation needs: one line

$fee _recorda_id_arr = array_values (Array_unique (Array_column ($feerecord, ' feerecordid '));

3 Function Hints:

Array_values ($arr) returns all values in the array and establishes a numeric index
Array_unique ($arr) array is de-weighed, but the returned result key value is not in order
Array_column ($arr, $key) takes out the multidimensional array, the key value = $key all element values, and makes up a numeric array

The above introduces the PHP array to heavy elements, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.