foreach 循环有问题。问题如下:
foreach($content as $c) {
$root->appendChild($node = $dom->createElement($table));
$node->setAttribute("id", $content['id']);
foreach($c as $key => $value) {
$node->appendChild($dom->createElement($key, $value));
}
}
$content 包含表中的所有数据集。所以 $c 应该只包含一个。这正是它的作用:
Array
(
[0] => 11
[id] => 11
[1] => admin
[username] => admin
[2] => $2a$08$tpTWqFtZq1KzyIfD/UYI2u5iyGQw.m0.TGJSWx5gwsb/RaJAmdULK
[password] => $2a$08$tpTWqFtZq1KzyIfD/UYI2u5iyGQw.m0.TGJSWx5gwsb/RaJAmdULK
[3] =>
[group] =>
[4] => 0
[deleted] => 0
)
因此,在第二个 foreach 循环中,它应该获取每个元素及其密钥并将其攻击到节点,但它只运行一次。如果我在 foreach 循环中转储 $key 和 $value,我只会得到 2 个值,0 和 11。这是正确的,但它应该运行 8 次,而不仅仅是一次。谁能告诉我我的错误在哪里?
$content 的编辑/内容:
array(2) {
[0]=>
array(10) {
[0]=>
string(2) "11"
["id"]=>
string(2) "11"
[1]=>
string(5) "admin"
["username"]=>
string(5) "admin"
[2]=>
string(60) "$2a$08$tpTWqFtZq1KzyIfD/UYI2u5iyGQw.m0.TGJSWx5gwsb/RaJAmdULK"
["password"]=>
string(60) "$2a$08$tpTWqFtZq1KzyIfD/UYI2u5iyGQw.m0.TGJSWx5gwsb/RaJAmdULK"
[3]=>
string(0) ""
["group"]=>
string(0) ""
[4]=>
string(1) "0"
["deleted"]=>
string(1) "0"
}
[1]=>
array(10) {
[0]=>
string(2) "25"
["id"]=>
string(2) "25"
[1]=>
string(6) "mlange"
["username"]=>
string(6) "mlange"
[2]=>
string(60) "$2a$08$X/fDcVsbrIE3sAHjU44aNOxQPe2Gg2wRDdd/YeRFT54rmdNucbJ5e"
["password"]=>
string(60) "$2a$08$X/fDcVsbrIE3sAHjU44aNOxQPe2Gg2wRDdd/YeRFT54rmdNucbJ5e"
[3]=>
string(0) ""
["group"]=>
string(0) ""
[4]=>
string(1) "0"
["deleted"]=>
string(1) "0"
}
}