max1234 Posted November 26, 2012 Share Posted November 26, 2012 Hi, I need to sort a multidimensional array. I know this should be very simple but am having some difficulty wrapping my head around it. I have an array of arrays containing order information. In each array there is a field for product name and I would like to sort the arrays by product name. So for example: $myarray[1,shoes] $myarray[2,wellies] $myarray[3,boots] $myarray[4,wellies] How do I sort $myarray so that it is ordered alphabetically? $myarray[3,boots] $myarray[1,shoes] $myarray[2,wellies] $myarray[4,wellies] I have tried sort and multisort but how do choose which variable to sort by? I don't want to sort by the number, I want to sort by the product name. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/271175-sorting-multidimensional-array/ Share on other sites More sharing options...
drmovi Posted November 26, 2012 Share Posted November 26, 2012 your array look like following key =>1 value=>shoes so sort() can perform a value sorting Quote Link to comment https://forums.phpfreaks.com/topic/271175-sorting-multidimensional-array/#findComment-1395095 Share on other sites More sharing options...
max1234 Posted November 26, 2012 Author Share Posted November 26, 2012 Hi drmovi, that was quite a simplified array. Perhaps I should have been more detailed. There are possibly up to 10 values in each array. How do I define which value is sorted? Quote Link to comment https://forums.phpfreaks.com/topic/271175-sorting-multidimensional-array/#findComment-1395099 Share on other sites More sharing options...
Iluvatar+ Posted November 26, 2012 Share Posted November 26, 2012 http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/ Quote Link to comment https://forums.phpfreaks.com/topic/271175-sorting-multidimensional-array/#findComment-1395102 Share on other sites More sharing options...
Iluvatar+ Posted November 26, 2012 Share Posted November 26, 2012 You could use ksort() also. Quote Link to comment https://forums.phpfreaks.com/topic/271175-sorting-multidimensional-array/#findComment-1395105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.