Home  >  Article  >  Backend Development  >  What is the method to remove duplicate values ​​from an array in php

What is the method to remove duplicate values ​​from an array in php

王林
王林Original
2020-11-09 16:42:461654browse

The way PHP removes duplicate values ​​from an array is to use the array_unique function to remove duplicate values, such as [array_unique($a)]. This function removes duplicate values ​​from an array and returns the filtered array.

What is the method to remove duplicate values ​​from an array in php

array_unique() function is used to remove duplicate values ​​from an array. If two or more array values ​​are the same, only the first value is retained, the other values ​​are removed, and the filtered array is returned.

(Learning video recommendation: java video tutorial)

Grammar:

array_unique(array)

Example:

<?php
$a=array("a"=>"red","b"=>"green","c"=>"red");
print_r(array_unique($a));
?>

Running results :

Array ( [a] => red [b] => green )

Related recommendations: php training

The above is the detailed content of What is the method to remove duplicate values ​​from an array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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