On Thu, Apr 22, 2010 at 2:12 PM, Ashley Sheridan
> I've not had to do this before, and now that I am, I've hit a bit of a
> Basically, I've an array that might look like this (the number of
> elements may vary, but the letter is always unique and remains a single
> 0 => '2h'
> 1 => '1d'
> 2 => '2w'
> And I need to sort them according to their letter. If I wasn't using
> classes, I could just use usort($array, 'custom_sort') but when I do
> that within my class, I'm told it can't find the function. I've tried
> usort($array, $this::custom_sort) and usort($array,
> $Gantt_Task::custom_sort), both of which throw up the rather frightening
> unexpected double colon error (if you've ever seen one you'll know what
> I'm on about!)
> Does anyone know how I can do a usort within a class without resorting
> to making my sorting function a global function that isn't part of the
> class? I'd rather keep this tidy and everything in the class that needs
> to be in it, so a random function sitting outside is something I want to
> avoid if possible.
> Alternatively, if anyone knows a better way than using usort I'm all
Try using an array to pass in the function:
usort($array, array('ClassName', 'staticMethodName'));
Nephtali: PHP web framework that functions beautifully