tags:

views:

105

answers:

4

Hi,

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?

A: 

The question was about invalid arguments passed for implode()

The 2nd argument for implode() must be an array.

$a in your sample code is not an array.

pavium
+1  A: 
$two = '';

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

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

No need for implode.

dfilkovi
+1  A: 

but easier way is:

$two = implode(',', $_POST['selr']);
dfilkovi
+1 . thanks for this one.
JPro
A: 

You're not passing an array to implode(), that's why it complains. Try this:

if (isset($_REQUEST['selr'])) {
    echo implode(',', $_REQUEST['selr']);
}
soulmerge