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!
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:
or cast to array: