The array_unique () function sorts the values of array elements as strings. then, only the first key name is retained for each value. ignore all subsequent key names, that is, deleting repeated elements in the array, the previous article describes how to delete the header, tail, and arbitrary elements in the PHP array. This article describes how to delete repeated elements in the array using the array_unique () function.
The array_unique () function sorts the values of array elements as strings. then, only the first key name is retained for each value. ignore all subsequent key names, that is, deleting repeated elements in the array,
The syntax format is as follows:
array arry_unique(array array)
The parameter array is the input array.
The following example causes the array_unique () function to delete repeated elements in the array. the sample code is as follows:
"; $ Result = array_unique ($ array_push); // delete the repeated elements in the array print_r ($ result); // output the deleted array?>
Output result:
The array_unique () function is only applicable to one-dimensional arrays and does not apply to multi-dimensional arrays. However, you can use array_unique () as the value in a two-dimensional array.
The following example uses the array_unique () function to delete duplicate elements in a two-dimensional array. the code is as follows :,
$value){ $temp_array[$key] = array_unique($value);}$array = $temp_array;echo "
";print_r($array);?>
Output result:
[Recommended tutorials]
1. related topic recommendations: php Array (Array)
2. related video course recommendations: Array statistical functions: count (), array_count_values () and array_unique ()
The preceding figure shows how to delete the repeated elements in the PHP array. For more information, see other related articles in the first PHP community!