我想我已經(jīng)回收了,大腦不再沸騰了。請告訴我如何刪除鍵中這些不需要的鍵?而且我的 foreach 似乎有點(diǎn)歪,我會很高興看到解決這個(gè)問題的提示。先感謝您。我對輸出有什么:Array( [0] => Array ( [0] => Array ( [id] => asdasd ) [1] => Array ( [server] => asdadsasd ) [2] => Array ( [login] => asdasdads ) [3] => Array ( [ip] => adsads ) [4] => Array ( [date] => dasadsads ) ) [1] => Array ( [0] => Array ( [id] => 12123123 ) [1] => Array ( [server] => 123213213 ) [2] => Array ( [login] => 321231123 ) [3] => Array ( [ip] => 213231213 ) [4] => Array ( [date] => 321213213 ) ))我需要做什么:Array( [0] => Array ( [id] => asdasd [server] => asdadsasd [login] => asdasdads [ip] => adsads [date] => dasadsads ) [1] => Array ( [id] => 12123123 [server] => 123213213 [login] => 321231123 [ip] => 213231213 [date] => 321213213 ))test2.php代碼:<?php //header('Content-Type: application/json'); $commands = array(); foreach($_POST as $key => $value) { foreach($_POST[$key] as $name => $val) { $commands[$name][] = array($key => $val); } } print_r($commands); //echo json_encode($commands, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);?>我試過了$commands[$name] = array($key => $val);,但他愚蠢地替換了意思并替換了一個(gè)新的意思,當(dāng)然。
1 回答

智慧大石
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
這對我有用->
<?php
header('Content-Type: application/json');
$commands = array();
foreach($_POST as $key => $value) {
foreach($_POST[$key] as $name => $val) {
$commands[$name][$key] = $val;
}
}
print_r($commands);
?>
- 1 回答
- 0 關(guān)注
- 177 瀏覽
添加回答
舉報(bào)
0/150
提交
取消