Jump to content


This topic is now archived and is closed to further replies.

Jim from Oakland

sorting arrays using second dimension keys

Recommended Posts


User 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]['Subject']="Car Color";

aItemsArray[2]['Subject']="Car Size";

aItemsArray[3]['Subject']="House Color";

aItemsArray[4]['Subject']="House Size";

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.

Share this post

Link to post
Share on other sites
this takes your array, shuffles it, then put it back into order again

$aItemsArray[1]['Subject']="Car Color";

$aItemsArray[2]['Subject']="Car Size";

$aItemsArray[3]['Subject']="House Color";

$aItemsArray[4]['Subject']="House Size";

shuffle ($aItemsArray);
echo '<pre>', print_r($aItemsArray, true), '</pre>';

echo '<pre>', print_r($aItemsArray, true), '</pre>';

Share this post

Link to post
Share on other sites
be careful to set up your array in this order. 1st set category then subject and at last response

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.