Mike521 Posted January 24, 2008 Share Posted January 24, 2008 Hi all, hopefully I can explain this correctly I have a 2-dimensional array that I need to loop through. dimension 1 may be something like: array( 1, 2, 3, 4, 5) dimension 2 may be something like array1 (1) = array( john, 947 ) array1 (2) = array( mike, 756 ) array1 (3) = array( jim, 1047 ) array1 (4) = array( chris, 999 ) array1 (5) = array( rick, 111 ) I need to loop through it all, but not in the order that array 1 presents everything. I need to go in the order of the numbers in array2's second variable. Ideally I would re-sort array 1 in order of array2's second variable, like so: array1 (1) = array( rick, 111 ) array1 (2) = array( mike, 756 ) array1 (3) = array( john, 947 ) array1 (4) = array( chris, 999 ) array1 (5) = array( jim, 1047 ) I hope it makes enough sense for someone to help me out! thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/87633-looping-through-2-dimensional-array-based-on-ascending-value-of-var-in-dim-2/ Share on other sites More sharing options...
resago Posted January 24, 2008 Share Posted January 24, 2008 create a 2nd array foreach item in array1 array2[item[1]]=item; then array2=values(array2); should reorder with 1-.... may have to do array copy instead of = Quote Link to comment https://forums.phpfreaks.com/topic/87633-looping-through-2-dimensional-array-based-on-ascending-value-of-var-in-dim-2/#findComment-448223 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.