Sorting a complicated array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Sorting a complicated array

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Sorting a complicated array

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Re: Sorting a complicated array

Post 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
Post Reply