Forum Moderators: coopster
I have a array as below:
$array = array(
array(0,0),
array(0,1),
array(0,1),
array(0,1),
array(2,2),
array(3,4),
array(1,0),
array(1,0),
array(4,3),
array(2,3),
array(2,2),
array(3,2)
);
I used method array_count_values to have the sorted array below:
Array
(
[0 - 0] => 1
[0 - 1] => 3
[1 - 0] => 2
[2 - 2] => 2
[2 - 3] => 1
[3 - 2] => 1
[3 - 4] => 1
[4 - 3] => 1
)
however, I would like to have the array looks like the one below:
Array
(
[0 - 0] => 1
[0 - 1] => 5
[2 - 2] => 2
[2 - 3] => 2
[3 - 4] => 2
)
because 0 -1 and 1 - 0 are the same results, same as the 2 - 3 and 3 - 2.
thanks for your help!
function my_array_count_vals($array) {
$return = array();foreach ($array as $a) {
$min = min($a);
$max = max($a);
if ($return["$min - $max"])
$return["$min - $max"]++;
else
$return["$min - $max"] = 1;
return $return;
}
Haven't tested, but it should give you an idea..