Home  >  Article  >  Backend Development  >  How to delete identical values ​​from php array

How to delete identical values ​​from php array

Guanhui
GuanhuiOriginal
2020-05-05 16:24:072256browse

How to delete identical values ​​from php array

php array deletes the same values

In PHP, you can use the "array_unique()" function to remove duplicate values ​​in the array , the usage of this function is "array_unique($array)", its parameter $array represents the array from which duplicate values ​​are to be removed, and the return value of this function is the array after removing duplicate values.


array_unique example

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

Output result:

Array
(
    [a] => green
    [0] => red
    [1] => blue
)

The above is the detailed content of How to delete identical values ​​from php array. 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
Previous article:php .= what does it meanNext article:php .= what does it mean