Jump to content

can this be done efficiently?


Michdd

Recommended Posts

Say I have an array of objects, each of these objects have an y property. Would it be possible to get the number that it would be in ascending order without being terribly inefficient? I think I explained that bad, so here's an example:

 

I have an array have contains 3 objects (Just for this example, it could contain many more).

 

1. object->y = 300;

2. object->y = 500;

3. object->y = 400;

 

if I was getting the order of object #2 it should be order 1 because it has the highest y value. I can think of a way to do this, but only in extremely inefficient ways.

Link to comment
https://forums.phpfreaks.com/topic/173255-can-this-be-done-efficiently/
Share on other sites

Sorting really isn't a very efficient thing.  For people it's easy to move something either mentally or physically around, but because of the rigid memory structures in computers, it's not as plain cut.

 

(It's not like a horribly time taking process or anything, I just mean that it's more complex than people think.  There are all kinds of algorithms and stuff that attempt to make it more efficient though.)

 

 

 

Anyway, I suggest making a usort() function.

 

http://php.net/usort

 

 

Example 3 should get ya started.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.