How To Remove Duplicate values from Array using PHP||EasyCoding45

 In this Tutorial,we are going to learn how we can remove duplicate values from Array.

Remove duplicate value means same value cannot be repeated.

This can be done by using Array_unique() function.

for Example :-- There are some values in Array i.e,[20,43,34,65,76,43,34].

So Output Should be :--[20,43,34,65,76].

  • We will use one HTML file To pass Multivalue as a parameter.
  • So to pass multiple value through HTML we must use comma between the values.

HTML Program :--

  1. <html>
  2. <body>
  3. <form method=get action=n_numbers.php>
  4. Enter Comma separated numbers : <input type=text name=t1><br>
  5. <input type=submit value=pass></br>
  6. </form>
  7. </body>
  8. </html>

And now PHP program :--

  1. <?php
  2. $arr=$_GET['t1'];
  3. $spl=explode(",",$arr);
  4. print_r(array_unique($spl));
  5. ?>
3) In line number 3 we have used explode() function so we can store multiple value in an array.
4)And By using Array_unique() we have removed duplicate values.

                                                                       HTML:--
PHP Output :--

Thank you💛



Comments