0

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!

3 Answers 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]);
Sign up to request clarification or add additional context in comments.

Comments

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

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.