kingW3
kingW3

Reputation: 439

PHP Foreach and unsetting variable

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

Upvotes: 1

Views: 163

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

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

Upvotes: 4

Related Questions