got a problem with a foreach loop. The problem is the following:
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 contains all the data sets from a table. So $c should contain only one. And thats exactly what it does:
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
)
So in the 2nd foreach loop, it should get every single element together with its key and attack it to the node, but its only running once. If i dump $key and $value inside the foreach loop, i only get 2 values, 0 and 11. Thats correct, but it should run 8 times, not only once. Can anybody tell me where my error is?
Edit/ Content of $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"
}
}
$cas reference? (&$c)