I have array A :
Input:
A ={2,3,2,1,3,2,0,3,2,0,11,7,9,2}
I want output to be Array B
Output:
B={0,1,2,3,7,9,11}
I have array A :
Input:
A ={2,3,2,1,3,2,0,3,2,0,11,7,9,2}
I want output to be Array B
Output:
B={0,1,2,3,7,9,11}
Your friends are: array_unique() and sort()
With these functions you can create the distinct list and sort it:
$a = {2,3,2,1,3,2,0,3,2,0,11,7,9,2}
$b = array_unique($a, SORT_NUMERIC)
sort($b, SORT_NUMERIC)
You have to filter/sort by distinct number values and order ascending..
Unique values: Select only unique array values from this array
Order values: http://www.w3schools.com/php/php_arrays_sort.asp
You need to get all unique values and then sort them.
array_unique()
removes all duplicate values.
sort()
sorts your values from low to high.
$B = array_unique($A);
sort($B);
//remove duplicate values from array using array_unique
$unique_array = array_unique($a);
//sort the resulting array
sort($unique_array);
//dump it to verify
var_dump($unique_array);
Input:
A ={2,3,2,{1},3,2,{0},3,2,0,11,7,9,{2}} I want output to be Array B
Output:
B={0,1,2,3,7,9,11}