JPro JPro - 4 months ago 25
PHP Question

using implode to combine multiple select

I have a php page like this :

<html>
<body>
<form method="post" action="catch_combo.php">
<select name="selr[]" multiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit">
</form>
</body>
</html>


I am trying to catch the selected values in catch_combo.php which looks like this:

<?php
$two;
if(isset($_REQUEST['selr']))
{
$one=$_POST['selr'];
foreach ($one as $a)
{
$two = implode(",", $a);
}
echo $two;
}
?>


When I run this it says

'Invalid arguments passed for implode' I am missing something?

Answer
$two = '';

if(isset($_REQUEST['selr']))
{

    $one=$_POST['selr'];
    foreach ($one as $a=>$value) 
    {
        $two .= ', '.$value;
    }
    echo $two;
}

No need for implode.