Looking for an optimized version of this algorithm! ! ! !

WBOY
Release: 2016-07-25 08:48:45
Original
804 people have browsed it
problems encountered in the project.
There are several small arrays in a large array, but the small arrays may be repeated, and the interface needs to return a non-duplicate array structure. I tried the built-in function array_merge() in PHP, but it cannot sort small arrays. Here's how I use it. I can only say that the efficiency is very low. If you see this article and have a good method, please tell me. :)
//$hotel_setting may contain repeated large arrays.
The small array structure is 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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template