Display Unique Number Values in a string using PHP

The funciton DisplayUniqueValues() will let you remove the duplicate values from a string array of numbers and sort out the resulting value that will be displayed.

Code:
 
<?php 

function DisplayUniqueValues($NumArray)
{
 //Remove the duplicated values 
 $uniques = array_unique(explode(",", $NumArray)); 
 
 //Sort out the unique values  
 $result = sort($uniques, SORT_NUMERIC);
 
 //Combine the result in a string using the separator ',' 
 $result = implode(',', $uniques); 

 return $result;
} 

 //USAGE
 $str_num = '12,13,14,12,12,12,12,11,14,90,78,78,91,90,92,89';
 
 echo DisplayUniqueValues($str_num); 

?>
Output should be:
11,12,13,14,78,89,90,91,92

Comments

Popular posts from this blog

How to Create a Configuration.INI Files in VB6

How to Make Windows Form Transparent using Visual Basic 6/VB6

How to Set Windows Form Always on Top of Other Applications in VB6