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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:05:16+00:00 2026-05-18T10:05:16+00:00

I have a question. I have this code in the first page: <input type=text

  • 0

I have a question.

I have this code in the first page:

<input type="text" name="number" id="number">
<input type="submit" name="button_add" id="button_add" value="add">
<? 
$i=0;
while($number>$i) { $i++; ?>
  <div align="left">
  <input type="text" name="text[<? echo $i; ?>]" id="text[<? echo $i; ?>]" /><? } 
?>

How do I define the array of fileds in the next page using $_POST vars?

  • 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-18T10:05:16+00:00Added an answer on May 18, 2026 at 10:05 am

    The entry in $_POST is itself an array, if that’s what you’re asking:

    for ($i = 0; $i < count($_POST['text']); ++$i) {
        // do something with this post:
        $_POST['text'][$i];
    }
    

    or:

    foreach ($_POST['text'] as $i => $text) {
        // do something with:
        $text;
        // Note: $text === $_POST['text'][$i]
    }
    

    Off-topic

    Always close your elements:

    <input type="text" name="number" id="number" />
    <input type="submit" name="button_add" id="button_add" value="add" />
    

    You also neglected to close the <div> wrapping the text[] inputs. If you don’t, your document is ill-formed and, though browsers will attempt to parse the document, there’s no guarantee they’ll do it the way you want.

    The default type for inputs is text. It doesn’t hurt to set the type attribute to “text”, but it isn’t necessary.

    Don’t rely on short tags; use the full <?php. Not all hosts will have them enabled, and they’re deprecated and will be going away soon (there’s been some talk about doing away with them before PHP 5).

    You don’t need to explicitly assign array indices for your input names; empty brackets will cause the value to be assigned to the end of the array. Also, ‘[‘ and ‘]’ aren’t valid characters for IDs.

    <input type="text" name="text[]" id="text_<?php echo $i; ?>" />
    

    A for loop is more appropriate than a while loop in your code. Though both do the same thing, they have different connotations (a while loop repeats while some static condition holds under changing circumstances; a for loop repeats over a sequence).

    for ($i=0; $i < $number; ++$i) {
    

    All together, we have:

    <input name="number" id="number" />
    <input type="submit" name="button_add" id="button_add" value="add" />
    <?php for ($i=0; $i < $number; ++$i): ?>
      <div align="left">
        <input name="text[]" id="text_<?php echo $i; ?>" />
      </div>
    <?php endfor; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code in my .aspx page. <input type=hidden id=fbinfo name=fbinfo value=
I have this view (DetailsContainer, first class in code section of this question) with
So I just have posted a question about this code (which was answered): $(document).ready(Main);
This is a follow up from my previous question I have this code basically
i have a question , i have this timer code in java that when
i have this simple question please. I have this part of code which sets
Today I came across this question: you have a code static int counter =
Recently I have seen this code in a WebSite, and my question is the
http://ideone.com/GKxcj this is my code. I have a question about the output so when
Quick question, What have I done wrong here. The purpose of this code is

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.