views:

131

answers:

2

Hello,

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!

+2  A: 

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]);
webbiedave
A: 
<select name="names[]" multiple="multiple">  
<option value="<?php echo($arr); ?>"><?php echo($arr); ?></option>  

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