1

我的代码是

<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()。结果是 Array ( [0] => Array ( [0] => Asset 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[]"" 运行此代码,但结果是
Array (

[0] => Asset Id 1
[1] => Asset Id 2
[2] => Asset Id 1
[3] => Asset Id 3

)

请帮我..

4

3 回答 3

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"
    }
  }
于 2012-09-07T05:07:18.870 回答
0
name="assed_id[1][]"

这会有所帮助

于 2012-09-07T05:03:12.467 回答
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>
于 2012-09-07T05:12:38.927 回答