jj kk jj kk - 6 months ago 29
PHP Question

Sort a Multidimensional PHP array by a specific key

I have a multidimensional PHP array. I want to sort it by

[point]
. Which means 3>2>1. I know how to use such functions like
usort() asort() aksort()
. However i could not succeed. Thanks.

Array (
[0] => Array ( [label] => @the big list of milfs
[value] => the big list of milfs
[id] => 3
[point] => 1 )
[1] => Array ( [label] => @the big list of porn -- free
[value] => the big list of porn -- free
[id] => 2
[point] => 2 )
[2] => Array ( [label] => @the big list of porn -- free
[value] => the big list of porn -- free
[id] => 2
[point] => 3 )
)

Answer

array_multisort

//$data - your array
$points = array_column($data, 'point');
array_multisort($points, SORT_DESC, $data);
print_r($data)
Comments