HTML分组输入在PHP中返回'array'而不是其值的数组

时间:2012-11-15 16:28:42

标签: php html

在使用括号表示法之前,我已将元素组合在一起,但我必须忽略某些内容。也许另外一双眼睛(或数千只眼睛)可以发现为什么会发生逆火。

foreach ( $record as $field => $value) {

if(strpos($value , '~') !== FALSE){ //All drop down lists are separated by ~
    $rows_of_dlist .= '<tr>';

$stored_field = explode ( "mlljx", $value );
$stored_field [0] = trim ( $stored_field [0] ); //Title of the list
$stored_field [1] = trim ( $stored_field [1] ); //Values of the list


$dlist = explode ( '~', $stored_field [1] );

foreach ( $dlist as $dlist ) {
    $list_values .= " <td><input type='checkbox' name='selected_option[]'value='$dlist'/> &nbsp; $dlist</td>";
}

$rows_of_dlist .= "<td align = 'center'>$stored_field[0]</td> $list_values</tr>";


<form id="all" name="all" method="POST" action="$page_name?page_view=report" >
    <table align="center" width = "100%" border = "2">  
        <th colspan = "1">Name Of Custom Drop-down List</th>
        <th colspan = "10">Drop-list Values</th>
        $rows_of_dlist      
        <tr>
            <td align = 'center' colspan='10'>
                        <input type="submit" value="Make PDF" name = "make_pdf"/>
            </td>
        </tr>
    </table>
</form>

发布值后,我测试POST数组:

  var_dump($_POST);
  exit;

然后它说即使我只选择一个框,$_POST['selected_option']也是'数组'。

1 个答案:

答案 0 :(得分:1)

我认为这是错误的:

foreach ( $dlist as $dlist ) {

不应该像

那样
foreach ( $dlist as $element) { ... do something with each $element ... }