- array('PHP', 'MySQL', 'PHP', 'JavaScript')
How to Remove Duplicate Values from an Array in PHP |
---|
Here is an array that has some duplicate values:
The following code will remove all duplicate values from an array using PHP array_unique() function:
The result array will have the values like the below:
Now, we will show you how to remove duplicate values with case/space insensitively from an array in PHP. If an array has duplicate values with a combination of upper/lower/word cases, the values need to be converted in the same latter case before applying the array_unique(). Also, we need to remove the space from values before duplicate comparison. The following code snippet removes duplicate values from the array with case and space insensitively using PHP array_map() and array_unique() functions.
Example:
Result array will be:
|
Published: | November 23, 2022 |
Author: | admin |
Category: | Full Tutorials |
Views: | 29 |
This article was posted in Full Tutorials. Bookmark the permalink. Follow comments with the RSS feed for this post.Post a Comment or leave a trackback: Trackback URL.
|
|