Sorting a complicated array
Posted: Fri Oct 22, 2010 1:33 pm
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
, 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
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'))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