PHP array_unique

1.函数的作用:移除数组中重复的值

2.函数的参数:

  @params array $array

  @params int $sort_flag

    SORT_REGULAR : 通常方法比较(不改变类型)

    SORT_NUMERIC : 数值方法比较

    SORT_STRING : 字符串的形式比较

    SORT_LOCAL_STRING : 先本地化,再按字符串比较

3.

例子一:

 1 <?php
 2 $array1 = range(1,500000,3);
 3 $array2 = range(1,500000,4);
 4 $arr = array_merge($array1,$array2);
 5 echo 'count :' .count($arr) . "
";
 6 
 7 $begin_time = microtime(true);
 8 array_keys(array_flip($arr));
 9 $end_time = microtime(true);
10 print_r($end_time - $begin_time);
11 
12 echo "
";
13 $begin_time = microtime(true);
14 array_flip(array_flip($arr));
15 $end_time = microtime(true);
16 print_r($end_time - $begin_time);
17 
18 echo "
";
19 $begin_time = microtime(true);
20 array_unique($arr);
21 $end_time = microtime(true);
22 print_r($end_time - $begin_time);

 例子二:

<?php
/*
 * equal to 'array_unique' on string or integer type comparing.
 */
$array = [1,2,4,3,3,5,7,9];
print_r(array_keys(array_count_values($array)));

例子三:

1 <?php
2 $array = ['abc','Abc','ABc','ABC','abc'];
3 print_r(array_diff_assoc($array,array_unique($array)));
学习记录,方便复习
原文地址:https://www.cnblogs.com/jingjingdidunhe/p/6918168.html