Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4604466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:18:00+00:00 2026-05-22T00:18:00+00:00

I currently construct a multi-dim array from my input. like so: (example) <form method=post

  • 0

I currently construct a multi-dim array from my input. like so: (example)

<form method=post action="testing.php">
<input name="response[0]['id']" type="hidden" value="<? echo $q1; ?>">
<input name="response[0]['answer']" type=text value=''>
<input name="response[1]['id']" type="hidden" value="<? echo $q2; ?>">
<input name="response[1]['answer']" type=text value=''>
<input name="response[2]['id']" type="hidden" value="<? echo $q3; ?>">
<input name="response[2]['answer']" type=text value=''>
<input name="response[3]['id']" type="hidden" value="<? echo $q4; ?>">
<input name="response[3]['answer']" type=text value=''>
<input type="submit" value="submit">
</form>

so that is successfully be POSTED. However I am trying to use a foreach to print out the values and I am getting it wrong.

EDIT my output array:

Array ( 
[0] => Array 
( 
['id'] => q1 
['answer'] => 1 
) 
[1] => Array 
( 
['id'] => q2 
['answer'] => 2 
) 
[2] => Array 
( 
['id'] => q3 
['answer'] => 3 
) 
[3] => Array 
( 
['id'] => q4 
['answer'] => 4 
)
) 

can somebody explain how i would extract the values with a foreach or even a better way?

many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:18:00+00:00Added an answer on May 22, 2026 at 12:18 am

    EDIT
    Note the apos (') are part of the name! Either change the HTML (response[0][id]) or do the following.

    The incoming array should look like:

    $response = array(
        0 => array("'id'" => ..., "'answer'" => ...),
        1 => array("'id'" => ..., "'answer'" => ...),
        2 => array("'id'" => ..., "'answer'" => ...),
        3 => array("'id'" => ..., "'answer'" => ...),
    );
    

    Thus,

    foreach ($response as $resp) {
        print 'ID=' . $resp["'id'"] . ', answer=' . $resp["'answer'"];
    }
    

    The problem: <input name="response[0]['answer']" /> will yield an array with 'answer' as key. I.e., the literal string with apos, not just answer. You should probably change the HTML to <input name="response[0][answer]" /> to avoid confusion. I will try and see if this is documented behavior. This behavior is indicated in the docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using Django to construct JSON encoded objects which a retrieved using
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently I'm doing some unit tests which are executed from bash. Unit tests are
I am currently writing a multi-threaded C++ server using Poco and am now at
I needed to write a script to enter multi-line input to a program (
I am currently trying to construct the area covered by a device over an
I'm currently playing with the Stack Overflow data dumps and am trying to construct
I am currently developing a site that users the jQuery superfish plugin to construct
Perl 5.10 introduced a proper switch construct with given/when and it seems like a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.