有一个具有以下格式的数组。 我使用array_chunk函数进行格式化,如下面的数组。
Array (
[0] => Array
(
[0] => Array
(
[SGST (2.5%)] => 2.5000
)
[1] => Array
(
[CGST (2.5%)] => 2.5000
)
)
[1] => Array
(
[0] => Array
(
[CGST (6%)] => 6.0000
)
[1] => Array
(
[SGST (6%)] => 6.0000
)
)
)
我需要以下列格式显示我的数组
Array
(
[0] => Array
(
[SGST (2.5%)] => 2.5000
[CGST (2.5%)] => 2.5000
)
[1] => Array
(
[CGST (6%)] => 6.0000
[SGST (6%)] => 6.0000
)
)
帮助创建这样的格式。谢谢
答案 0 :(得分:0)
尝试array_map,array_reduce与array_merge
的组合要了解有关php.net上使用过的功能检查功能doc的更多信息
<?php
$array = array (
'0' => array
(
'0' => array
(
'SGST (2.5%)' => '2.5000'
),
'1' => array
(
'CGST (2.5%)' => '2.5000'
)
),
'1' => array
(
'0' => array
(
'CGST (6%)' => '6.0000'
),
'1' => array
(
'SGST (6%)' => '6.0000'
)
)
);
echo '<pre>';
$processed = array_map(function($a) { return array_reduce($a, 'array_merge', array()); }, $array);
print_r($processed);
<强>输出强>
Array
(
[0] => Array
(
[SGST (2.5%)] => 2.5000
[CGST (2.5%)] => 2.5000
)
[1] => Array
(
[CGST (6%)] => 6.0000
[SGST (6%)] => 6.0000
)
)