我的代码是
<tr>
<td><input type="text" name="batch_code[]"/></td>
<td><input type="text" name="description[]"/></td>
<td><input type="text" size="12" name="qty[]"/></td>
<td>
<select id="asset_id" class="asset_id" name="asset_id[][]" multiple="multiple">
<option class="dropdownlist">Asset Id 1</option>
<option class="dropdownlist">Asset Id 2</option>
<option class="dropdownlist">Asset Id 3</option>
</select>
</td>
</tr>
<tr>
<td><input type="text" name="batch_code[]"/></td>
<td><input type="text" name="description[]"/></td>
<td><input type="text" size="12" name="qty[]"/></td>
<td>
<select id="asset_id" class="asset_id" name="asset_id[][]" multiple="multiple">
<option class="dropdownlist">Asset Id 1</option>
<option class="dropdownlist">Asset Id 2</option>
<option class="dropdownlist">Asset Id 3</option>
</select>
</td>
</tr>
我想在数组中获取数组。但是如果我得到这个asset_id的print_r()。结果是 排列 ( [0] =&gt;排列 ( [0] =&gt;资产ID 1 )
[1] => Array
(
[0] => Asset Id 2
)
[2] => Array
(
[0] => Asset Id 1
)
[3] => Array
(
[0] => Asset Id 3
)
)
但我想要的是什么
Array
(
[0] => Array
(
[0] => Asset Id 1
[1] => Asset Id 2
)
[1] => Array
(
[0] => Asset Id 1
[1] => Asset Id 3
)
)
我使用一个方括号“name =”asset_id []“”运行此代码,但结果是
排列
(
[0] => Asset Id 1
[1] => Asset Id 2
[2] => Asset Id 1
[3] => Asset Id 3
)
请帮帮我..
答案 0 :(得分:2)
试试这个:
<tr>
<td><input type="text" name="batch_code[]"/></td>
<td><input type="text" name="description[]"/></td>
<td><input type="text" size="12" name="qty[]"/></td>
<td>
<select id="asset_id" class="asset_id" name="asset_id[0][]" multiple="multiple">
<option class="dropdownlist">Asset Id 1</option>
<option class="dropdownlist">Asset Id 2</option>
<option class="dropdownlist">Asset Id 3</option>
</select>
</td>
</tr>
<tr>
<td><input type="text" name="batch_code[]"/></td>
<td><input type="text" name="description[]"/></td>
<td><input type="text" size="12" name="qty[]"/></td>
<td>
<select id="asset_id" class="asset_id" name="asset_id[1][]" multiple="multiple">
<option class="dropdownlist">Asset Id 1</option>
<option class="dropdownlist">Asset Id 2</option>
<option class="dropdownlist">Asset Id 3</option>
</select>
</td>
</tr>
<强>更新强> 我出于好奇尝试了这个,结果是必要的:
["asset_id"]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(10) "Asset Id 1"
[1]=>
string(10) "Asset Id 2"
}
[1]=>
array(2) {
[0]=>
string(10) "Asset Id 1"
[1]=>
string(10) "Asset Id 3"
}
}
答案 1 :(得分:0)
name="assed_id[1][]"
这将有助于
答案 2 :(得分:0)
为什么使用二维数组。使用asset_id []而不是asset_id [] []
更正代码
<tr>
<td><input type="text" name="batch_code[]"/></td>
<td><input type="text" name="description[]"/></td>
<td><input type="text" size="12" name="qty[]"/></td>
<td>
<select id="asset_id" class="asset_id" name="asset_id[]" multiple="multiple">
<option class="dropdownlist">Asset Id 1</option>
<option class="dropdownlist">Asset Id 2</option>
<option class="dropdownlist">Asset Id 3</option>
</select>
</td>
</tr>
<tr>
<td><input type="text" name="batch_code[]"/></td>
<td><input type="text" name="description[]"/></td>
<td><input type="text" size="12" name="qty[]"/></td>
<td>
<select id="asset_id" class="asset_id" name="asset_id[]" multiple="multiple">
<option class="dropdownlist">Asset Id 1</option>
<option class="dropdownlist">Asset Id 2</option>
<option class="dropdownlist">Asset Id 3</option>
</select>
</td>
</tr>