ID: 22006 Comment by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Wont fix Bug Type: Feature/Change Request Operating System: Linux PHP Version: 4.2.0 New Comment:
That's quite true - you can do it. But it's not straightforward, especially when the array has 3 or more dimensions. How about the following: 1)Write a function to do it the way I suggested. 2)Put this in the documentation as a pseudo array-function. That has the advantages of: i)Minimum development work required ii)The function is there as needed (and can be searched for conveniently) iii)Really good documentation. Regards Richard p.s. My proposal only works when sorting along a line parallel to a cartesian axis of the array. Of course, one could sort according to any line which cuts the n-space of the array - but, while that is more general, its use would be somewhat rare. Previous Comments: ------------------------------------------------------------------------ [2003-02-02 01:06:51] [EMAIL PROTECTED] There are many examples and user comments on the manual page for usort() which show how to accomplish this using existing functionality. http://www.php.net/manual/en/function.usort.php ------------------------------------------------------------------------ [2003-02-01 23:48:23] [EMAIL PROTECTED] Oops - that doesn't quite make sense. We want to be able to sort on "the 3rd column" or "the 7th row" if it's 2-D; in the case of 3-D, we need to be able to sort on "(the line determined by depth=4 and height=3)". So a better prototype would be: my_array_sort(my_array,i,j,-,l) meaning: sort by index k, where the other indices have values of i,j,l respectively) [Array multisort will work, but only to sort by column; therefore if one wants to sort by ROW, the array must be redesigned]. Sorry the first comment isn't mathematically sensible! ------------------------------------------------------------------------ [2003-02-01 23:24:16] [EMAIL PROTECTED] Consider an array of arrays : myarray["$i"]["$j"]...["$n"] I'd like to see a function which will allow me to sort this on the nth array index. Something like: my_array_function(myarray, n) where n is the dimension to sort on. This would make it easy to sort any array by row, column, depth, etc Sorry if this feature already exists - I have spend 2 hours reading the manual and googling for it to no avail. I know there are ways to get around it, but a dedicated function would be nice. Thanks. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22006&edit=1