我有一个名为的数组$result_for_json_all
Array
(
[0] => Array
(
)
[1] => Array
(
[0] => Array
(
[CurrencyAbbreviation] => AUD
[DateOfCurrencyRate] => 2012-12-11
[NumberOfInputRow] => 1
[FinalCurrencyRate] => 0.571
)
)
[2] => Array
(
[0] => Array
(
[CurrencyAbbreviation] => CAD
[DateOfCurrencyRate] => 2013-12-22
[NumberOfInputRow] => 4
[FinalCurrencyRate] => 0.48
)
[1] => Array
(
[NumberOfInputRow] => 2
[FinalCurrencyRate] =>
)
[2] => Array
(
[NumberOfInputRow] => 3
[FinalCurrencyRate] =>
)
)
)
想要得到
Array
(
[0] => Array
(
[CurrencyAbbreviation] => AUD
[DateOfCurrencyRate] => 2012-12-11
[NumberOfInputRow] => 1
[FinalCurrencyRate] => 0.571
)
[1] => Array
(
[CurrencyAbbreviation] => CAD
[DateOfCurrencyRate] => 2013-12-22
[NumberOfInputRow] => 4
[FinalCurrencyRate] => 0.48
)
[2] => Array
(
[NumberOfInputRow] => 2
[FinalCurrencyRate] =>
)
[3] => Array
(
[NumberOfInputRow] => 3
[FinalCurrencyRate] =>
)
)
基于此https://stackoverflow.com/a/9416851/2118559创建的代码
function flatten($result_for_json_all) {
$arr = array();
foreach($result_for_json_all as $k => $v) {
if(is_array($v)) {
$arr = array_merge($arr, flatten($v, $k));
}
else{
$arr[$k] = $v;
}
}
return $arr;
}
echo '<pre>';
print_r(flatten($result_for_json_all));
echo 'result_for_json_all<pre>';
但是得到
Array
(
[CurrencyAbbreviation] => AUD
[DateOfCurrencyRate] => 2013-12-22
[NumberOfInputRow] => 3
[FinalCurrencyRate] =>
)
请建议需要纠正什么以获得必要的结果