find duplicate values in an array using php

find duplicate values in an array using php

Many times we need to find duplicate values in an array using php. Using php language this is very easy. For checking the duplicate array value array_unique function is very useful.

There too many array and string functions available in php. PHP itself gives very useful methods for finding the duplicate values from array element.

There are multiple ways to find the duplicate strings. you can use loop and strpos method but using following code snippet, it is very easy to find the duplicate values from an array.

find duplicate values in an array using php

find duplicate values in an array using php
find duplicate values in an array using php

Here I am giving you very simple php example:


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
 $array1 = array("banana","apple","pear","banana");

 if (count(array_unique($array1)) < count($array1))
 echo 'Duplicate entry found in array';
 else
 echo 'No Duplicate values found in array';
 ?>

Output:  Duplicate entry found in array

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “find duplicate values in an array using php”

Leave a Reply to WP Themes Cancel reply

Your email address will not be published.