The optimized version of this algorithm!!!!

Source: Internet
Author: User
Problems encountered in the project.
There are several decimal groups in a large array, but the decimal group may be duplicated, and the interface needs to return a non-repeating array structure. The built-in function array_merge () in PHP has been tried, and it is not possible to sort the decimal groups. Here's how I use it. I can only say that the efficiency is very low, if you see this article, there is a good way, please tell me. :)
$hotel _setting may contain duplicate large arrays.
The decimal group structure is an array (' hotel_adt_cnt ' = ' = ', ' hotel_chd_cnt ' = ' = ');
    1. $hotel _unique = Array ();
    2. while (1) {
    3. $cmp = Array_shift ($hotel _setting);
    4. $repeat = false;
    5. foreach ($hotel _setting as $val) {
    6. if ($val [' hotel_adt_cnt '] = = $cmp [' hotel_adt_cnt '] && $val [' hotel_chd_cnt '] = = $cmp [' hotel_chd_cnt ']) {
    7. $repeat = true;
    8. Break
    9. }
    10. }
    11. if (! $repeat)
    12. {
    13. $hotel _unique[] = $cmp;
    14. }
    15. if (count ($hotel _setting) = = 0) {
    16. Break
    17. }
    18. }
    19. $hotel _setting = $hotel _unique;
Copy Code
  • 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.