Small example of php array de-weight

Source: Internet
Author: User
    1. function Assoc_unique ($arr, $key) {
    2. $tmp _arr = Array ();
    3. foreach ($arr as $k = = $v) {
    4. if (In_array ($v [$key], $tmp _arr)) {
    5. Unset ($arr [$k]);
    6. } else {
    7. $tmp _arr[] = $v [$key];
    8. }
    9. }
    10. Sort ($arr);
    11. return $arr;
    12. }
    13. $AA = Array (
    14. Array (' id ' = = 123, ' name ' = ' Zhang San '),
    15. Array (' id ' = = 123, ' name ' = ' John Doe '),
    16. Array (' id ' = = 124, ' name ' = ' Harry '),
    17. Array (' id ' = ' = ', ' name ' = ' Zhao Liu '),
    18. Array (' id ' = = 126, ' name ' = ' Zhao Liu ')
    19. );
    20. $key = ' name ';
    21. Assoc_unique (& $aa, $key);
    22. Print_r ($AA);
    23. ?>
Copy Code

you may be interested in the article:PHP to create an array of methods introduced PHP using Array_unique to determine if the array has the same value in the PHP array and a small example of the loop PHP in a multidimensional array to find the method of the specific value of the enhanced version of Array_ Unique function (supports two-dimensional arrays) Learn PHP ordering of multidimensional arrays PHP Array callback filter function Array_filter () Examples of applications PHP extracts variables from an array of functions and application instances PHP code that sorts a multidimensional array by a value randomly extracts some elements of PHP code from the array

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