On Thu, 2010-04-22 at 14:26 -0400, Adam Richardson wrote:
> On Thu, Apr 22, 2010 at 2:12 PM, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
> 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
> 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
> 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
> 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
> 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
Thanks! I literally just found that answer as your reply came through.
It's a bit of a facepalm moment here right now, as I'm ashamed to say
that the answer was on the manual pages all along, which I'd failed to
read properly :-/