1

I am calling the following function:

function buildInStmt($array)
{
    if (is_array($array)) {
        $in = implode(',', $array);
    } else $in = "'" . $array . "'";
    var_dump("in=" . $in); 
    var_dump("$array=" . $array); 
    return $in;
}

...

    if (!isset($_REQUEST["form-type"]) || empty($_REQUEST["form-type"])) {
        throw new Exception('You must select a form type.');       
    }
    $forms = buildInStmt(array($_REQUEST["form-type"]));

The var_dumps from the function are returning:

string 'in=Array' (length=8)

string 'Array=Array' (length=11)

string 'in=Array' (length=8)

string 'Array=Array' (length=11)

string 'in=1' (length=4)

string 'Array=Array' (length=11)

The var_dump(array($_REQUEST["form-type"])); from the call returns:

array (size=1) 0 => array (size=2) 0 => string '4' (length=1) 1 => string '7' (length=1)

Why isn't implode returning a comma delimited string?

Iff you elect to downvote this question, please explain the reason so I can learn from my mistakes.

3
  • 3
    Because you have an array of arrays, or so it seems. Commented Jun 5, 2016 at 15:31
  • 1
    Thanks, Francisco. I am passing an array from ajax. Works now. Commented Jun 5, 2016 at 15:35
  • Perfect, glad to know it :) Commented Jun 5, 2016 at 15:37

1 Answer 1

1
array (size=1) 0 => array (size=2) 0 => string '4' (length=1) 1 => string '7' (length=1)

Is roughly equivalent to

$var = [
  0 => [
    0 => '4',
    1 => '8'
  ]
]

So it seems that you have an array of arrays. Try not adding an unneeded array from your code:

buildInStmt($_REQUEST["form-type"])
Sign up to request clarification or add additional context in comments.

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.