1

I'm passing a PDO prepare parameter array into the foreach statement so that I can modify the data. I'm modifying some data based on the prefix. Here's the example from my code:

foreach($param as $key => $t)
{
    if(strpos($key,"int")===0)
    {
        $t = (int) $param[$key];
        $key = str_replace("int","",$key);
        unset($param[$key]);
        $param[$key] = $t;
    }
}

I'm not sure how to unset those array elements with int as prefix, and I can't execute query because of PDO error:

Invalid parameter number: number of bound variables does not match number of tokens

1 Answer 1

4

You need to unset($param[$key]) BEFORE you change $key.

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.