【发布时间】:2019-12-07 00:55:01
【问题描述】:
希望我能解释一下,以便于理解。我很挣扎,所以我来这里希望能得到一些帮助:)
我正在组合/合并几个表。它似乎工作得很好,但您会注意到下面的代码行。
$records = array_merge($records, $records3);
我需要对其进行修改,使其包含“来源”。
例如:
{
"tags": [
{
"id": "1",
"name": "video",
"cssanimate": "flipInY",
source:{
"mp4": "1.mp4",
"ogg": ""
}
}
]
},
这就是它现在的显示方式。这是错误的!
{
"tags": [
{
"id": "1",
"name": "video",
"cssanimate": "flipInY",
"mp4": "1.mp4",
"ogg": ""
}
]
},
这是我的代码:
$result = $mysqli->query("SELECT id, username, volume, name, content, image, cssanimate, group_name FROM table_1 ORDER BY id ");
$result2 = $mysqli->query("SELECT id, username, volume, name, content, image, cssanimate, group_name FROM table_2 ORDER BY position");
$result3 = $mysqli->query("SELECT id, name, cssanimate, mp4, ogg FROM table_3 ORDER BY id ");
$records2 = array();
while ($row2 = $result2->fetch_assoc()) {
$records2[] = array('tags' => array($row2));
}
$records3 = array();
while ($row3 = $result3->fetch_assoc()) {
$records3[] = array('tags' => array($row3));
}
// Place "table_2" and "table_3" in every 10th position
$counter = 0;
while ($row = $result->fetch_assoc()) {
$counter++;
if(($counter % 10 == 0) || $counter==1 ) {
$records = array_merge($records, $records2);
$records = array_merge($records, $records3);
}
$records[] = array('tags' => array($row));
}
// Make is pretty
$json = json_encode($records, JSON_PRETTY_PRINT);
......
感谢任何帮助!
【问题讨论】:
-
您可能会发现array_merge_recursive() 或array_replace_recursive() 很有帮助。
-
谢谢!会看看。