Re: Using usort in Cake

2009-08-11 Thread DiRN

Sorry for the mixed quotes.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Using usort in Cake

2009-08-11 Thread DiRN

For future refernce, you would use:

usort($fruits, array(&$this, 'cmp"));
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Using usort in Cake

2009-08-10 Thread John R

Perfect, thank you.



On Aug 10, 9:32 am, brian  wrote:
> Try the Set 
> class.http://book.cakephp.org/view/640/Sethttp://blogs.bigfish.tv/adam/2008/03/24/sorting-with-setsort-in-cakep...
>
>
>
> On Mon, Aug 10, 2009 at 9:46 AM, John R 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Using usort in Cake

2009-08-10 Thread brian

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 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Using usort in Cake

2009-08-10 Thread John R

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---