Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post Array 3

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Is it permitted to make a form posted variable an array?

eg.
$_POST['SOMETHING'][1]
$_POST['SOMETHING'][2]
etc,etc.

instead of:
$_POST['SOMETHING1']
$_POST['SOMETHING2']

Thanks
 
This comes into play when you have more than one field with the same name on your form:
Code:
<form>
    <input name="test" [...] />
    <input name="test" [...] />
    <input name="test" [...] />
</form>
You would then access these as:
Code:
$_POST["test"][0]
$_POST["test"][1]
$_POST["test"][2]

More often, though, you will encounter this when trying to parse multi-selects:
Code:
<form>
    <select multiple="true" name="test[]">
        <option value="1" selected="true">One</option>
        <option value="2" selected="true">Two</option>
        <option value="3" selected="true">Three</option>
    </select>
</form>
And you would then access these as:
Code:
$_POST["test"][0]
$_POST["test"][1]
$_POST["test"][2]

Take Care,
Mike
 
Excellent, or hip,hip,array. That makes my life a bit easier. Many thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top