| | |
Creating a multi-dimensional Session variable
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 3
Reputation:
Solved Threads: 0
Hi again,
I'm stumped. I'd like to store results from a questionnaire in a multi-dimensional session variable to tally the number of questions answered after the entire questionnaire is completed. Users choose selections from checkboxes, so I have that info coming from an array. I was hoping I could just create an array of answers, keyed by the question, but I'm having some issues. Here is a code snippet.
When I print out the contents of the array, it gives me:
Array ( [0] => 31 [1] => 32 [2-2] => Array ( [0] => 31 [1] => 32 [2-2] => Array *RECURSION* ) )
I feel like it should be:
Array( [2-2] => Array ( [0] => 31 [1] => 32 )
At least that's what I want to happen. I also only have one php page and depending on what's passed into the url, different questions are shown. Because of this, it seems like my answers array isn't adding the new arrays.
Weird thing is when I hardcoded everything, this worked just fine. Now that I want it more dynamic, it isn't working. Any ideas? Or maybe there's some other way I'm not seeing. TIA!
I'm stumped. I'd like to store results from a questionnaire in a multi-dimensional session variable to tally the number of questions answered after the entire questionnaire is completed. Users choose selections from checkboxes, so I have that info coming from an array. I was hoping I could just create an array of answers, keyed by the question, but I'm having some issues. Here is a code snippet.
PHP Syntax (Toggle Plain Text)
//items is the checkbox //$curr is a string created designating the question $answers = $_POST['items']; if (count($answers) > 0) { $_SESSION['answers'][$curr]=$answers; print_r($_SESSION['answers']); }
When I print out the contents of the array, it gives me:
Array ( [0] => 31 [1] => 32 [2-2] => Array ( [0] => 31 [1] => 32 [2-2] => Array *RECURSION* ) )
I feel like it should be:
Array( [2-2] => Array ( [0] => 31 [1] => 32 )
At least that's what I want to happen. I also only have one php page and depending on what's passed into the url, different questions are shown. Because of this, it seems like my answers array isn't adding the new arrays.
Weird thing is when I hardcoded everything, this worked just fine. Now that I want it more dynamic, it isn't working. Any ideas? Or maybe there's some other way I'm not seeing. TIA!
•
•
Join Date: Jun 2007
Posts: 54
Reputation:
Solved Threads: 0
Try the
print_r($_SESSION['answers']);
before you set to see how it looks.
This might help with the debugging.
print_r($_SESSION['answers']);
before you set to see how it looks.
This might help with the debugging.
Steve Stedman - Software Development Professional
Questions about anything?
Questions about anything?
![]() |
Similar Threads
- Session Variable clashing (ASP.NET)
- Losing session variable problem...help! (ASP)
- Need help passing a multi-dimensional array (C++)
- session variable undefined in MX 6.1, works in CF 5 (ColdFusion)
- Session variable (ASP.NET)
- session variable:again (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: Need Help getting sum of one key from flat file
- Next Thread: Email addrress in Sessions
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





