How to delete duplicate values ​​in an array in php

王林
Release: 2023-03-04 13:10:01
Original
1836 people have browsed it

How to delete duplicate values ​​in an array in php: You can use the built-in function array_unique() to achieve this. The array_unique() function is used to remove duplicate values ​​from the array and return the filtered array. If there are multiple array values ​​with the same value, only the first value is retained.

How to delete duplicate values ​​in an array in php

php has a built-in function array_unique() that can be used to remove duplicate values ​​in an array.

(Recommended tutorial: php graphic tutorial)

array_unique() function is used to remove duplicate values ​​in the array and return the filtered array.

If two or more array values ​​are the same, only the first value is retained and the other values ​​are removed.

Grammar:

array_unique(array)
Copy after login

(Video tutorial recommendation: php video tutorial)

Example:

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

Output:

Array ( [a] => red [b] => green )
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template