Php array unique
From w3cyberlearnings
Contents |
PHP function array_unique
This function removes duplicate values from an array.
Syntax array_unique
- array: array input
array_unique(array);
Example 1
- Keep 'a'=>30, remove 'c'=>30
<?php $score= array('a'=>30,'b'=>20,'c'=>30); $r = array_unique($score); print_r($r); ?>
Output
Array ( [a] => 30 [b] => 20 )
Example 2
<?php $score= array('a'=>30,'b'=>20,'c'=>30,'x'=>30,'y'=>32,'bx'=>20); $r = array_unique($score); print_r($r); ?>
Output
Array ( [a] => 30 [b] => 20 [y] => 32 )
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys