Try the Set class. http://book.cakephp.org/view/640/Set http://blogs.bigfish.tv/adam/2008/03/24/sorting-with-setsort-in-cakephp-12/
On Mon, Aug 10, 2009 at 9:46 AM, John R<[email protected]> wrote: > > I have an array that I need to sort by an associative key. PHP's usort > () function is what I need, however it won't work inside a controller. > > Example: > > function cmp($a, $b) > { > return strcmp($a["fruit"], $b["fruit"]); > } > > $fruits[0]["fruit"] = "lemons"; > $fruits[1]["fruit"] = "apples"; > $fruits[2]["fruit"] = "grapes"; > > usort($fruits, "cmp"); > > I am pretty sure the reason it doesn't work, is because I would have > to call $this->cmp(), not just cmp() like the function is probably > doing. Anyone have any idea how to get around this? Or a better way to > sort arrays by key in Cake? > > Thanks! > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
