包含 php 变量的 $_POST[] 数组内爆时出错

发布于 2024-09-10 08:54:29 字数 1177 浏览 4 评论 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]: 在线 /home/content/r/e/s/reslife4/html/duty/schedule.php 中传递的参数无效15

这就是我创建 $_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++; }?>

任何人都可以看到我做错了什么吗?

谢谢!

I am trying to implode an array in a $_POST[]. I am doing this inside of a loop which searches for values in ~31 arrays...$_POST['1'], $_POST['2'], $_POST['3'], etc.

I am trying to do this with:

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++;

}

I am receiving the following error, though:

Warning: implode() [function.implode]: Invalid arguments passed in /home/content/r/e/s/reslife4/html/duty/schedule.php on line 15

This is how I create the $_POST[] variables:

<?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++; }?>

Can anyone see what I am doing wrong?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

记忆消瘦 2024-09-17 08:54:29

如果您传递数组以外的其他内容作为 implode 的第二个参数(例如,当未选择任何选项时),您将收到警告。您可以有条件地内爆:

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

或转换为数组:

$names = implode(',', (array)$_POST['names_'.$i]);

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]);
蝶舞 2024-09-17 08:54:29
<select name="names[]" multiple="multiple">  
<option value="<?php echo($arr); ?>"><?php echo($arr); ?></option>  

<?php foreach($_POST['names'] as $key => $value):  
    echo $value;  
?>
<select name="names[]" multiple="multiple">  
<option value="<?php echo($arr); ?>"><?php echo($arr); ?></option>  

<?php foreach($_POST['names'] as $key => $value):  
    echo $value;  
?>
木格 2024-09-17 08:54:29
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++;
}
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++;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文