我将向foreach语句传递一个PDO prepare参数数组,以便修改数据。我正在根据前缀修改一些数据。下面是我代码中的示例:

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;
    }
}

我不知道如何设置这些以int为前缀的数组元素,而且由于PDO错误,我无法执行查询:
Invalid parameter number: number of bound variables does not match number of tokens

最佳答案

您需要在更改unset($param[$key])之前$key

关于php - PHP Foreach和未设置变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14385941/

10-12 05:35
查看更多