我想我已经回收了,大脑不再沸腾了。请告诉我如何删除键中这些不需要的键?而且我的 foreach 似乎有点歪,我会很高兴看到解决这个问题的提示。先感谢您。我对输出有什么: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);,但他愚蠢地替换了意思并替换了一个新的意思,当然。
1 回答
智慧大石
TA贡献1946条经验 获得超3个赞
这对我有用->
<?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 关注
- 141 浏览
添加回答
举报
0/150
提交
取消