你需要自己把它弄平。没有内置的单行函数可以做到这一点。
function flattenArr($arr, $key, &$result) {
foreach ($arr as $k => $v) {
if (is_array($v)) {
flattenArr($v, $key . "[$k]", $result);
} else {
$result[$key . "[$k]"] = $v;
}
}
}
$obj = array("a" => array("b" => "c", "d" => array("1"=>array(1,2,3,5),"2", "3")));
$result = array();
flattenArr($obj, "", $result);
foreach ($result as $k => $v) {
echo "result$k = $v\n";
}
输出:
result[a][b] = c
result[a][d][1][0] = 1
result[a][d][1][1] = 2
result[a][d][1][2] = 3
result[a][d][1][3] = 5
result[a][d][2] = 2
result[a][d][3] = 3
这可能不会像现在这样,您可能需要对其进行一些修改。高温高压