开发者

Error imploding $_POST[] array containing php variable

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>开发者_如何学Python;
<?php $i++; }?>

Can anyone see what I am doing wrong?

Thanks!


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]);


<select name="names[]" multiple="multiple">  
<option value="<?php echo($arr); ?>"><?php echo($arr); ?></option>  

<?php foreach($_POST['names'] as $key => $value):  
    echo $value;  
?>


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜