I have been trying to sort a keyed array by an object instance variable value contained within using usort() and it does not seem like the right tool to be using. Was hoping someone has some advice on sorting an object as shown below.
Thanks in advance!
$ary = array("apple" => object DatePrice ("date" => "2015-12-01", "price" => 3),
"orange" => object DatePrice ("date" => "2015-12-02", "price" => 4),
"banana" => object DatePrice ("date" => "2015-12-01", "price" => 0.50),
"pear" => object DatePrice("date" => "2015-12-01", "price" => 1),
);
Desired result:
$ary = array("orange" =>object DatePrice("date" => "2015-12-02", "price" => 4),
"apple" => object DatePrice("date" => "2015-12-01", "price" => 3),
"pear" => object DatePrice("date" => "2015-12-01", "price" => 1),
"banana" => object DatePrice("date" => "2015-12-01", "price" => 0.50));
Found this post: Sort array of objects by object fields
But I need to sort a keyed array of objects..