Page 1 of 1

Sorting a complicated array

Posted: Fri Oct 22, 2010 1:33 pm
by lshaw
Hello,

I have code looping through $_POST data, and for each row echoing all the data, but the only problem is I need the data to be sorted. I need to change the loop to put the data in an array, but I have tried several arrays, and they have not sorted how i want them to. I need the data to stay in rows as if it was being sorted in a MYSQL database, but i need to put it in a database AFTER it has been sorted.

I have tried these arrays

Code: Select all

array(array(value1[0]=>'test',value1[1]='test1')array(value2[0]='test2',value2[1]='test3'))
, and so on for all data, but when you sort the array with sort by one index, i.e. value1 the indexes are not maintained and the array goes into the wrong order. Using asort nothing happened at all.
I tried creating a row for all the values for each set of data, but no sorting works.

What would be the best way to sort this kind of array so that when sorting by one column/row, all other indexes on this column/row remain with the one that the array should be sorted by.

Thanks, Lewis

Re: Sorting a complicated array

Posted: Fri Oct 22, 2010 2:42 pm
by AbraCadaver
What does the post array look like, what do you want it to look like after and what do you want to sort on?

Re: Sorting a complicated array

Posted: Fri Oct 22, 2010 2:52 pm
by lshaw
I have sorted it out now using this website: http://firsttube.com/read/sorting-a-mul ... -with-php/

It is a very useful function