array_unique() function in PHP, How to display unique elements of an Array in PHP, How to remove duplicate elements from an array PHP


array_unique() function in PHP, How to display unique elements of an Array in PHP, How to remove duplicate elements from an array PHP

If you want to make sure all the elements in a provided array are unique, use the array_unique() function. This function removes duplicity from the Array and shrinks the array if there are in fact duplicate values. The element keys are not renumbered when this function is complete.

example

<?php
$grades = array(87,88,98,74,56,94,67,98,49) ;
echo "<b>The all elements of the Array are</b><br/>";
foreach($grades as $grade)
echo "$grade<br/>" ;
$uniqueGrades = array_unique($grades);
echo "<b>The unique elements in the Array are</b><br/>";
foreach($uniqueGrades as $ugrade)
echo "$ugrade<br/>" ;
?>

Output

The all elements of the Array are
87
88
98
74
56
94
67
98
49
The unique elements in the Array are
87
88
98
74
56
94
67
49


{ 1 comments... read them below or add one }

Admin said...

thanks dear...

Post a Comment