php remove duplicates from array
<?php
$fruits_list = array('Orange', 'Apple', ' Banana', 'Cherry', ' Banana');
$result = array_unique($fruits_list);
print_r($result);
?>
Output:
Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry )
php remove duplicates from array
<?php
$fruits_list = array('Orange', 'Apple', ' Banana', 'Cherry', ' Banana');
$result = array_unique($fruits_list);
print_r($result);
?>
Output:
Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry )
array unique php
<?php
// Syntax: array_unique(array $array, int $flags = SORT_STRING): array
// Desc: Removes duplicate values from an array
$arr = Array("red", "red", "green", "blue", "blue", "white");
echo "<pre>";
print_r($arr);
echo "</pre> <br><br>";
$arrUnique = array_unique($arr);
echo "<pre>";
print_r($arrUnique);
echo "</pre> <br><br>";
/* -------- output -----------
Array
(
[0] => red
[1] => red
[2] => green
[3] => blue
[4] => blue
[5] => white
)
Array
(
[0] => red
[2] => green
[3] => blue
[5] => white
)
*/
?>
check duplicate data in array php
$counts = array_count_values($array);
$duplicate_title = array_filter($array, function ($value) use ($counts) {
return $counts[$value] > 1;
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us