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:

<html>
    <body>
        <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" />
        </form>
    </body>
</html>

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

<?php
    print_r($_POST);
?>

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

Array(
    [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!! :)

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?

No extraction required, just count $_POST['label'] :)

commented: Thank you so much!! +1

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

Here's my solution.

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

    for ($i = 0; $i < $labels; $i++)
    {
      echo $_POST["label"][$i]."<br />";
    }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.