Jim from Oakland Posted September 4, 2006 Share Posted September 4, 2006 PhreaxUser responses to individual forms are stored in arrays as shown below. I will gather all such results into one large results array with the same structure/keys. I'd sure appreciate your assistance with a way to sort the results array by each of the three second dimension keys, as described below. Responses from one form:aItemsArray[1]['Category']=1;aItemsArray[1]['Subject']="Car Color";aItemsArray[1]['Response']="Blue";aItemsArray[2]['Category']=1;aItemsArray[2]['Subject']="Car Size";aItemsArray[2]['Response']="Small";aItemsArray[3]['Category']=2;aItemsArray[3]['Subject']="House Color";aItemsArray[3]['Response']="Orange";aItemsArray[4]['Category']=2;aItemsArray[4]['Subject']="House Size";aItemsArray[4]['Response']="Medium";For the results array: The order (of the first dimension numeric "index" keys) of the results array reflects a) items being grouped (sorted) by category, b) within each category items are sorted by Subject and c) within each subject items are sorted by Response. Link to comment https://forums.phpfreaks.com/topic/19695-sorting-arrays-using-second-dimension-keys/ Share on other sites More sharing options...
Barand Posted September 4, 2006 Share Posted September 4, 2006 this takes your array, shuffles it, then put it back into order again[code]<?php$aItemsArray[1]['Category']=1;$aItemsArray[1]['Subject']="Car Color";$aItemsArray[1]['Response']="Blue";$aItemsArray[2]['Category']=1;$aItemsArray[2]['Subject']="Car Size";$aItemsArray[2]['Response']="Small";$aItemsArray[3]['Category']=2;$aItemsArray[3]['Subject']="House Color";$aItemsArray[3]['Response']="Orange";$aItemsArray[4]['Category']=2;$aItemsArray[4]['Subject']="House Size";$aItemsArray[4]['Response']="Medium";shuffle ($aItemsArray);echo '<pre>', print_r($aItemsArray, true), '</pre>';array_multisort($aItemsArray); echo '<pre>', print_r($aItemsArray, true), '</pre>';?>[/code] Link to comment https://forums.phpfreaks.com/topic/19695-sorting-arrays-using-second-dimension-keys/#findComment-85929 Share on other sites More sharing options...
sasa Posted September 4, 2006 Share Posted September 4, 2006 be careful to set up your array in this order. 1st set category then subject and at last response Link to comment https://forums.phpfreaks.com/topic/19695-sorting-arrays-using-second-dimension-keys/#findComment-85939 Share on other sites More sharing options...
Barand Posted September 4, 2006 Share Posted September 4, 2006 Good point Link to comment https://forums.phpfreaks.com/topic/19695-sorting-arrays-using-second-dimension-keys/#findComment-85941 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.