Jump to content

shuffle() an array as an element of root array?


jcanker

Recommended Posts

I'm creating a quick survey app for my son's cub scout pack's end-of-year surveys.  There are two sets of questions: those where they want the responses to be completely anonymous and those questions where we need to know who filled out the response (people volunteering for positions, etc)

 

I'm storing the responses in the db as two separate arrays, $anon and $nonAnon

$anon[0] will be an array containing all the questions:

$anon[0][0] = Survey question # 1

$anon[0][1] = Survey question #2, etc.

 

The responses will be stored as arrays and placed in $anon as the 2nd element:

$anon[1][0][0] = first response, answer to the first question

$anon[1][0][1] = first resopnse, answer to the 2nd question

$anon[1][1][0] = 2nd response, answer to the 1st question

Etc.

 

The pack leadership is concerned that no one would be able to reconstruct which anon response belonged to whom by matching up the order of the anon answers with the non-anon answers.  Therefore I'd like to shuffle at least the anon responses.

 

The long answer would be to build a temp array using the elements in $anon[1] and then shuffle that array and then reassign it to $anon[1].

Is there a way to use shuffle directly on $anon[1] without having to build a temporary array, shuffling it, then replacing the elements of $anon[1]?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.