UK [ju?ni:k] US [ju?nik]
adj. Only, only; unique, unique; unusual, special; extraordinary
php array_unique() function syntax
Function:Remove duplicate values ??in the array
Syntax: array_unique(array)
Parameters:
Parameters | Description |
array | Required. Specifies an array. |
sortingtype | Optional. Specifies how array elements/items are compared. Possible values: SORT_STRING - Default. Compare items as strings. SORT_REGULAR - Arrange each item in regular order (Standard ASCII, does not change type) SORT_NUMERIC - Treat each item as a number. SORT_LOCALE_STRING - Treat each item as a string, based on the current locale (can be changed via setlocale()). |
Description: First sort the values ??as strings, then only retain the first encountered key name for each value, and then ignore all The key name behind. This does not mean that the first occurrence of the same value in an unsorted array will be preserved.
php array_unique() function example
<?php $a=array("a"=>"php中文網(wǎng)","b"=>"西門","c"=>"php中文網(wǎng)"); print_r(array_unique($a)); ?>
Run instance?
Click the "Run instance" button to view the online instance
Output:
Array ( [a] => php中文網(wǎng) [b] => 西門 )
<?php $b=array("1"=>"php中文網(wǎng)","2"=>"滅絕師太","c"=>"php中文網(wǎng)",'4' => "歐陽克"); print_r(array_unique($b)); ?>
Run Instance?
Click the "Run Instance" button to view the online instance
Output:
Array ( [1] => php中文網(wǎng) [2] => 滅絕師太 [4] => 歐陽克 )