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 :--
- <html>
- <body>
- <form method=get action=n_numbers.php>
- Enter Comma separated numbers : <input type=text name=t1><br>
- <input type=submit value=pass></br>
- </form>
- </body>
- </html>
And now PHP program :--
- <?php
- $arr=$_GET['t1'];
- $spl=explode(",",$arr);
- print_r(array_unique($spl));
- ?>
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.
Comments
Post a Comment