Hi,
I'm having problems with uasort. I have a shopping cart class in a session array like this:
And I want to use uasort to sort this array by SupplierID so the order of the _cart keys would be 0, 2, 1.
Here's my code for the uasort:
Any ideas why it's not sorting?
I'm having problems with uasort. I have a shopping cart class in a session array like this:
Code:
shopping_cart Object
(
[_cart] => Array
(
[0] => Array
(
[ProductID] => 21
[SupplierID] => 2
[quantity] => 5
)
[1] => Array
(
[ProductID] => 18
[SupplierID] => 4
[quantity] => 1
)
[2] => Array
(
[ProductID] => 22
[SupplierID] => 2
[quantity] => 2
)
)
)
And I want to use uasort to sort this array by SupplierID so the order of the _cart keys would be 0, 2, 1.
Here's my code for the uasort:
Code:
function by_supplierid($a, $b) {
if ($a["SupplierID"] == $b["SupplierID"]) {
return 0;
}
return ($a["SupplierID"] < $b["SupplierID"]) ? -1 : 1;
}
function get_items() {
// return all the items
uasort($this->_cart, "by_supplierid");
return($this->_cart);
}
Any ideas why it's not sorting?