0

我正在尝试在 $_POST[] 中内爆一个数组。我在一个循环中执行此操作,该循环在 ~31 个数组中搜索值...$_POST['1']、$_POST['2']、$_POST['3'] 等。

我正在尝试这样做:

while($i <= $_SESSION['daysInMonth']){

$month = $_SESSION['month'];
$day = $i;
$names = implode(',',$_POST['names_'.$i]);
$region = $_SESSION['region'];
$date = date("Y").'-'.$month.'-'.$day;

echo("$names");

$i++;

}

但是,我收到以下错误:

警告:implode() [function.implode]:第 15 行 /home/content/r/e/s/reslife4/html/duty/schedule.php 中传递的参数无效

这就是我创建 $_POST[] 变量的方式:

<?php $i=1; while($i <= $daysInMonth){?>
            <table align="center" style="width: 435px">
                <tr>
                    <td class="style1"><p><select name="names_<?php echo($i); ?>[]" multiple="multiple">
                    <?php foreach($email_array as $arr){ ?>
                        <option><?php echo($arr); ?></option>
                    <?php } ?>
                    </select></p></td>
                </tr>
            </table>
<?php $i++; }?>

谁能看到我做错了什么?

谢谢!

4

3 回答 3

2

If you pass something other than an array as the second argument to implode (say, when no options were selected), you will receive the warning. You can either conditionally implode:

if (!empty($_POST['names_'.$i])) 
// implode

or cast to array:

$names = implode(',', (array)$_POST['names_'.$i]);
于 2010-07-19T19:31:08.273 回答
0
<select name="names[]" multiple="multiple">  
<option value="<?php echo($arr); ?>"><?php echo($arr); ?></option>  

<?php foreach($_POST['names'] as $key => $value):  
    echo $value;  
?>
于 2010-07-19T20:36:12.127 回答
0
while($i <= $_SESSION['daysInMonth']){
    $names = (array)$_POST['names_'.$i];
    $month = $_SESSION['month'];
    $day = $i;
    $names = implode(',',$names);
    $region = $_SESSION['region'];
    $date = date("Y").'-'.$month.'-'.$day;

    echo("$names");

    $i++;
}
于 2015-08-11T23:58:43.497 回答