English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The Problem :

I have an array of data and every piece of data in this array is itself an array of data, for each element of the array I create a new object based on the data, for example :

...
class dynamic{
function dynamic($DATA){
$this->name=$DATA[0]
$this->value_1=$DATA[1]
$this->value_2=$DATA[2]
}
}
...
$DATA=array(array('testa',1,2),array('testb',2,1));
for($x=0;$x $this->OBJECT[$x]=new dynamic($DATA[$x]);
}
...


Don't ask me why it's done like this and don't ask me to change it, this is the way it needs to be for the other classes to work.

Now, later on in another class I do a sort($this->OBJECT) and so far it will sort by 'name' ascending or descending, name being the first variable... If I change that to another variable I can order by that variable...

My question is simple... The answer, I fear, may be beyond the majority of Y!Answers users...

How do I define which variable to sort by and which sort function should I be using to do this..?

2006-12-21 03:29:07 · 1 answers · asked by just_another_user 3 in Computers & Internet Programming & Design

using usort() and uksort(), and spenfing the time to figure out what I have to do with them, are my final option... I spotted those from the PHP.net manual comments and figured that they would work in some way...

I am sure that there should be a simple way of doing this without writing a comparison function though, surely..? In my mind it's 99% working, all I need to do is tell sort to use "value_1" and not "name", I can do that by changing the order of the variables on the object, so I don't see why I can't just specify the order myself in some way...

*starts to sweat*

2006-12-21 03:58:25 · update #1

1 answers

I'm not sure that this is an answer but try to use a usort or uksort
function for sorting an array by values using a user-defined comparison function.

2006-12-21 03:37:19 · answer #1 · answered by Ana 6 · 0 0

fedest.com, questions and answers