newman Posted October 5, 2006 Share Posted October 5, 2006 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]=3but it creates an array like this :[0]=1[1]=2[2]=3[3]=1[4]=2[5]=3what's the solution to have an array like the one above ?thanks in advance . Quote Link to comment https://forums.phpfreaks.com/topic/23094-php-and-select-element/ Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/23094-php-and-select-element/#findComment-104394 Share on other sites More sharing options...
akitchin Posted October 5, 2006 Share Posted October 5, 2006 if you want the latter, you'll have to specify the key in the select names:[code]<select multiple name="addr[0]">[/code]and so on. Quote Link to comment https://forums.phpfreaks.com/topic/23094-php-and-select-element/#findComment-104412 Share on other sites More sharing options...
newman Posted October 7, 2006 Author Share Posted October 7, 2006 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/23094-php-and-select-element/#findComment-105462 Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 [code]<select name="addr[one][1]"><option value="1"><option value="2"><option value="3"></select><select name="addr[two][1]"><option value="4"><option value="5"><option value="6"></select>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23094-php-and-select-element/#findComment-105481 Share on other sites More sharing options...
akitchin Posted October 7, 2006 Share Posted October 7, 2006 redarrow's extra [1] is totally unnecessary, but perhaps changing the index you give in the input name to a string rather than a number will help. Quote Link to comment https://forums.phpfreaks.com/topic/23094-php-and-select-element/#findComment-105702 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.