Jump to content

php and select element


newman

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 )

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.