I have an array I need to sort by a field numerically, but it almost seems like php cannot do this, I've come close with the sorting function in This thread.
Here is a sample of my array that I need to sort numerically by the [sla] field.
Array
(
[0] => Array
(
[caseNumber] => 126
[contact_last_name] => Blah
[no_of_pcs] =>
[status] => Open
[building] => Blah
[location] => G52-11
[date] =>
[schdtime] =>
[date_assigned] =>
[assigner] => Blah
[sla] => 10.1
[sla_sort] =>
)
[1] => Array
(
[caseNumber] => 1035
[contact_last_name] => Blah
[no_of_pcs] =>
[status] => Equipment received
[building] => Blah
[location] => NA
[date] =>
[schdtime] =>
[date_assigned] =>
[assigner] => Blah
[sla] => 3
[sla_sort] =>
)
[2] => Array
(
[caseNumber] => 1030
[contact_last_name] => Blah
[no_of_pcs] =>
[status] => Equipment received
[building] => Blah
[location] => NA
[date] =>
[schdtime] =>
[date_assigned] =>
[assigner] => Blah
[sla] => 11.4
[sla_sort] =>
)
[3] => Array
(
[caseNumber] => 1031
[contact_last_name] => NA
[no_of_pcs] =>
[status] => Equipment received
[building] => Blah
[location] => NA
[date] =>
[schdtime] =>
[date_assigned] =>
[assigner] => Blah
[sla] => 2.9
[sla_sort] =>
)
Originally this array is queried from my database, & the sla field was varchar. I tried to use settype() inside the sort function as this field should remain as text, but have since changed it to float as part of my trouble shooting.
Currently when I sort this, I get the order:
[0]
[2]
[3]
[1]
But what I need is:
[3]
[1]
[0]
[2]
Numerically by the sla field! I can't believe this is so difficult. Before I founf the above thread, all I could get with any of the PHP sorting functions was a "1" when I used print_r.
Any help would be greatly appreciated!
-Sam