0

我给这个函数一个数组。

function updateColors($mysqli, $variables){

var_dump($variables);

foreach($variables as $key=>$value) {



    if (is_int($key) && $value){
        error_log("changing: " . $key . " to " .  $value);

        $mysqli->select_db("hotel");

        $sql = $mysqli->prepare("UPDATE `statuses`
        SET  `color` =  ?
        WHERE  `ID` =  ?;
        ");

        $sql->bind_param('si', $value, $key);

        if($sql->execute())
            return("Colors updated.");
        else
            return("Unexpected error while updating colors.");

    } else 
    error_log("NOT changing: " . $key . " to " .  $value);

}

}

这是结果var_dump

array(11) { 
["statcolor0"]=> string(6) "000000" 
[0]=> string(12) "rgb(0, 0, 0)"
["statcolor1"]=> string(6) "000000"
[1]=> string(12) "rgb(0, 0, 0)"
["statcolor2"]=> string(6) "000000"
[2]=> string(12) "rgb(0, 0, 0)"
["statcolor3"]=> string(6) "000000"
[3]=> string(12) "rgb(0, 0, 0)"
["statcolor4"]=> string(6) "000000"
[4]=> string(12) "rgb(0, 0, 0)"

["UpdateColors"]=> string(13) "Update Colors" }

但是,看起来我的 foreach 循环没有正确遍历数组中的所有值。这是结果error_log

[15-Apr-2013 15:08:37] NOT changing: statcolor0 to 000000
[15-Apr-2013 15:08:37] changing: 0 to rgb(0, 0, 0)

没有别的!奇怪的是,数组中的大多数项目都丢失了,并且没有记录在错误日志中。这是为什么?

4

0 回答 0