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 8932639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:21:31+00:00 2026-06-15T09:21:31+00:00

PHP will automatically convert <input type=text name=foo[0] value=x /> <input type=text name=foo[1] value=y />

  • 0

PHP will automatically convert

<input type="text" name="foo[0]" value="x" />
<input type="text" name="foo[1]" value="y" />

into

$_POST['foo'] = array(
    0 => 'x', 
    1 => 'y'
);

Which is what you want most of the time. However, in this case I would like this not to happen. Is there anyway to tell PHP to not do this?

I realize I could parse php://input myself, but I’d rather not do that if I can avoid it.

I also don’t have the option of renaming the input names.

  • 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-06-15T09:21:32+00:00Added an answer on June 15, 2026 at 9:21 am

    By using the brackets [] you explicitly tell PHP to create an array, just don’t use the brackets:

    <input type="text" name="foo_0" value="x" />
    <input type="text" name="foo_1" value="y" />
    

    The fields will be available in the $_POST array as $_POST['foo_0'] and $_POST['foo_1'].

    If you don’t have influence on the markup (which is weird, since you could always change them client side) you need to flatten the array.

    $post = array();
    
    foreach ($_POST as $key => $value) {
        if (!is_array($value)) {
            $post[$key] = $value;
        } else {
            foreach ($value as $foo => $item) {
                $post[$foo] = $item;
            }
        }
    }
    

    Or read some great input on array flattening.

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

Sidebar

Related Questions

I created a PHP function that will automatically turn URLs into links, link Twitter
I've been told that by passing an array into CURLOPT_POSTFIELDS will automatically do the
I am making a script in which php will fwrite and it ads it
To generate the following markup: <label class=foo>Bar</label> The PHP will look something like: <?php
I am writing a new application in PHP which will be released to the
I've got a html / php form which will add values to a a
I'm preparing a function in PHP to automatically convert a string to be used
I have built a webpage, splashcreen.html , that when someone loads index.php will automatically
I wrote my database class in PHP. __construct() method will automatically connect the application
I'm wondering if anyone knows of a PHP setting that will automatically escape double

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.