0
Hello, everyone. I have the following multidimensional array in PHP:
Array (
[0] => Array ( [0] => teste0 [1] => 1 )
[1] => Array ( [0] => teste1 [1] => 1 )
[2] => Array ( [0] => teste2 [1] => 2 )
[3] => Array ( [0] => teste3 [1] => 2 )
[4] => Array ( [0] => teste4 [1] => 2 )
[5] => Array ( [0] => teste5 [1] => 3 )
[6] => Array ( [0] => teste6 [1] => 4 )
[7] => Array ( [0] => teste7 [1] => 4 )
)
I would like to rank this array according to the amount of equal values that are at [1] (numeric). This would produce the following result:
Array (
[0] => Array ( [0] => teste2 [1] => 1 )
[1] => Array ( [0] => teste3 [1] => 1 )
[2] => Array ( [0] => teste4 [1] => 1 )
[3] => Array ( [0] => teste0 [1] => 2 )
[4] => Array ( [0] => teste1 [1] => 2 )
[5] => Array ( [0] => teste6 [1] => 4 )
[6] => Array ( [0] => teste7 [1] => 4 )
[7] => Array ( [0] => teste5 [1] => 3 )
)
How to rank using PHP or Javascript?
Why did a "teste2" disappear from the first to the second example and appeared a "teste1"?
– Woss
Use the function
array_multisort
– Valdeir Psr
If it is for the amount of equal values, the value should not appear
2
first ? This is the one that has the most "occurrences".– Isac
You want to order, that’s it?
– Ivan Ferrer
Gives a look here, and see if it helps you. It helped me.
– Ivan Ferrer
In this case, in the first array, since the value 2 is the most repeated, it becomes the new one placed first. The result is its elements receiving the value 1 in the result array.
– LauBF
I’ll take a look at this function and the link.
– LauBF