Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

w2ksp4.exe, WwwxxXdbf, procmail "FROM_MAILER" patch, Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table, 800c5000, setgid operation not permitted, pciehp: acpi_pciehprm on IBM, WWWXXX.DBF

Links

XODOX
Impressum

#1: Using usort in a class

Posted on 2010-04-22 20:12:05 by Ashley Sheridan

--=-ni8+XbsTRaXPKJAe8IXh
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I've not had to do this before, and now that I am, I've hit a bit of a
wall:

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
character):

Array(
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
ears!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-ni8+XbsTRaXPKJAe8IXh--

Report this message

#2: Re: Using usort in a class

Posted on 2010-04-22 20:25:55 by Ashley Sheridan

--=-W44acRO2vU50+0y5+L2J
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Thu, 2010-04-22 at 14:26 -0400, Adam Richardson wrote:

> On Thu, Apr 22, 2010 at 2:12 PM, Ashley Sheridan
> <ash@ashleysheridan.co.uk> wrote:
>
> I've not had to do this before, and now that I am, I've hit a
> bit of a
> wall:
>
> 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
> character):
>
> Array(
> 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
> ears!
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
> Try using an array to pass in the function:
>
>
>
> usort($array, array('ClassName', 'staticMethodName'));
>
>
> Adam
>
>
> --
> Nephtali: PHP web framework that functions beautifully
> http://nephtaliproject.com
>

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 :-/

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-W44acRO2vU50+0y5+L2J--

Report this message

#3: Re: Using usort in a class

Posted on 2010-04-22 20:26:56 by Adam Richardson

--00148530af20a7ac6c0484d774ee
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Apr 22, 2010 at 2:12 PM, Ashley Sheridan
<ash@ashleysheridan.co.uk>wrote:

> I've not had to do this before, and now that I am, I've hit a bit of a
> wall:
>
> 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
> character):
>
> Array(
> 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
> ears!
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
Try using an array to pass in the function:

usort($array, array('ClassName', 'staticMethodName'));

Adam

--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com

--00148530af20a7ac6c0484d774ee--

Report this message

#4: Re: Using usort in a class

Posted on 2010-04-22 20:39:26 by Adam Richardson

--00c09f923843578f700484d7a1c2
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Apr 22, 2010 at 2:25 PM, Ashley Sheridan
<ash@ashleysheridan.co.uk>wrote:

> On Thu, 2010-04-22 at 14:26 -0400, Adam Richardson wrote:
>
> On Thu, Apr 22, 2010 at 2:12 PM, Ashley Sheridan <ash@ashleysheridan.co.uk>
> wrote:
>
> I've not had to do this before, and now that I am, I've hit a bit of a
> wall:
>
> 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
> character):
>
> Array(
> 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
> ears!
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
> Try using an array to pass in the function:
>
>
>
> usort($array, array('ClassName', 'staticMethodName'));
>
>
>
> Adam
>
>
> --
> Nephtali: PHP web framework that functions beautifully
> http://nephtaliproject.com
>
>
> 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
> :-/
>
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
No problem ;)

Adam

--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com

--00c09f923843578f700484d7a1c2--

Report this message