How to Remove Duplicate Values from Array in PHP?
It is pretty simple to delete duplicate values from PHP Array. But sometimes we confuse for how can we remove. But PHP provide pre-define function array_unique that can help to remove duplicate values from Array.
array_unique() through we can get only unique value from array. So, you can see bellow example i have 34 value two times but when i use array_unique() then it will return only unique value as bellow output:
Example:
<?php
$myArray = [11, 34, 56, 78, 34, 11, 23];
$myArrayNew = array_unique($myArray);
print_r($myArrayNew);
?>
Output:
Array
(
[0] => 11
[1] => 34
[2] => 56
[3] => 78
[6] => 23
)
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Reset Array Keys in PHP?
- How to Remove Multiple Keys from PHP Array?
- PHP - How to Reindex Array Key After Unset Key?
- How to Get Specific Key Value from Multidimensional Array PHP?
- How to Set Value as Key in PHP Array?
- How to Convert Array Values to Lowercase in PHP?
- How to Convert Object into Array in PHP?
- How to Remove Specific Element by Value from Array in PHP?
- How to Get Maximum Key Value of Array in PHP?
- How to Remove Empty Values from Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Remove Null Values from Array in PHP?