I have an array that I'm simply trying to order by a score
key that contains the value that I'm trying to sort by. The desired results would change the order of the array below to display the index in the following order: [0]
, [2]
, [1]
.
I'm looping through the results which are pulled from a database. I'm creating a key named score
and then pushing the $row2
array in to a separate array because if I use mysql_data_seek
it gets rid of the score
key.
Also it's creating an unwanted key score
at the bottom.
How can I best clean this up and make sure the results are ordered high to low as desired?
$my_array = array();
while ($row2 = mysql_fetch_assoc($result2))
{
//score determined here
//$row2['score'] = ...more math, variable is numeric, not a string
array_push($array_page,$row2);
}
Current undesired results...
Array
(
[0] => Array
(
[score] => 7
)
[1] => Array
(
[score] => 2
)
[2] => Array
(
[score] => 4
)
[score] =>
)
Desired results...
Array
(
[0] => Array
(
[score] => 7
)
[2] => Array
(
[score] => 4
)
[1] => Array
(
[score] => 2
)
)
order by score
in your query.