Ok, so I'm learning PHP (and quite enjoying myself so far).

I'm making a web page that will have a list of text boxes for the user to type info in. The boxes will be created dynamically via JavaScript (later on in development), and the id/name of the box will be equal to a php array (called label[]). There could be any amount of boxes.

For the problem, I've got an example HTML file that represents the problem:

        <form action="test.php" method="post">
            <input type="text" name="label[]" /><br />
            <input type="text" name="label[]" /><br />
            <input type="text" name="label[]" /><br />
            <input type="submit" value="submit" />

And of course, here's the test.php file:


Rather simple, right? If I type 3 names in, and press submit, here's what I get:

    [label] => Array(
        [0] => bob
        [1] => william
        [2] => andy

I need to extract the array label out of $_POST, and then I need to find out how many items it has in it so I can get the information I need. Remember, there could be any amount label[] entries in the array.

Any help would be greatly appreciated!! :)

7 Years
Discussion Span
Last Post by josephe

Thank you for your quick response, Will! I'm familiar with count() (still new to me), but I still don't know how to extract the sub array label out of $_POST, so I can count it's items. Any help with that so I can count it afterwards?


That really cleared it up for me! Thanks for your time!

Here's my solution.

    $labels = count($_POST["label"]);
    echo $labels."<br />";

    for ($i = 0; $i < $labels; $i++)
      echo $_POST["label"][$i]."<br />";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.