Jump to content

Recommended Posts

hi . i have an array of multiple select elements :

<select multiple name="addr[]">

<option value=1>first choice
<option value=2>second choice
<option value=3>third choice

</select>

<select multiple name="addr[]">

<option value=1>first choice
<option value=2>second choice
<option value=3>third choice

</select>
i want these two to be in 2 different indexes :

\[0\]=1
\[0\]=2
\[0\]=3

[1]=1
[1]=2
[1]=3


but it creates an array like this :

[0]=1
[1]=2
[2]=3
[3]=1
[4]=2
[5]=3

what's the solution to have an array like the one above ?
thanks in advance .

Link to comment
https://forums.phpfreaks.com/topic/23094-php-and-select-element/
Share on other sites

you are using the same array name in your select tags? are you wanting to have 2 seperate arrays like this:

array1[0]
array1[1]
array1[2]

array2[0]
array2[1]
array2[2]

or are you wanting a 2d array that looks like this:

array[0][0]
array[0][1]
array[0][2]
array[1][0]
array[1][1]
array[1][2]
thanks for the replies . i tested what akitchin said :

<select name="addr[0]">
<option value="1">
<option value="2">
<option value="3">
</select>

<select name="addr[1]">
<option value="4">
<option value="5">
<option value="6">
</select>

but i get an array like this . the last option of each select element:

Array ( [0] => 3 [1] => 6 )
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.