我跟随两个动态增长的阵列。
第一个数组
Array
(
[Development Fund] => Array
(
[0] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 01-Dec-2015
[totalAmountPaid] => 49000
[tdsRate] => 2
[totalDudections] => 980
)
[1] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 01-Mar-2016
[totalAmountPaid] => 4000
[tdsRate] => 2
[totalDudections] => 80
)
[2] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 23-Mar-2016
[totalAmountPaid] => 19000
[tdsRate] => 2
[totalDudections] => 380
)
)
[Registration Fee] => Array
(
[0] => Array
(
[LedgerID] => 5739b50b6e3dce450e8b4567
[LedgerName] => Registration Fee
[PanITNO] => ITR00123
[dateOfPayment] => 02-Jan-2016
[totalAmountPaid] => 1000
[tdsRate] => 10
[totalDudections] => 100
)
)
[Purchase1] => Array
(
[0] => Array
(
[LedgerID] => 573c321e6e3dcec3228b4567
[LedgerName] => Purchase1
[PanITNO] => ITR00123
[dateOfPayment] => 02-Jan-2016
[totalAmountPaid] => 8000
[tdsRate] => 2
[totalDudections] => 160
)
)
)
第二个数组
Array
(
[Development Fund] => Array
(
[0] => Array
(
[Amountdeposited] => 1000
[dateOfDeposited] => 01-Jan-2016
[challaNumber] => 2
)
[1] => Array
(
[Amountdeposited] => 50000000
[dateOfDeposited] => 03-Mar-2016
[challaNumber] => 5555
)
[2] => Array
(
[Amountdeposited] => 90000
[dateOfDeposited] => 24-Mar-2016
[challaNumber] => 999
)
)
)
我需要输出如下所示,基于密钥。
最终数组
Array
(
[Development Fund] => Array
(
[0] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 01-Dec-2015
[totalAmountPaid] => 49000
[tdsRate] => 2
[totalDudections] => 980
[Amountdeposited] => 1000
[dateOfDeposited] => 01-Jan-2016
[challaNumber] => 2
)
[1] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 01-Mar-2016
[totalAmountPaid] => 4000
[tdsRate] => 2
[totalDudections] => 80
[dateOfDeposited] => 03-Mar-2016
[challaNumber] => 5555
)
[2] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 23-Mar-2016
[totalAmountPaid] => 19000
[tdsRate] => 2
[totalDudections] => 380
[Amountdeposited] => 90000
[dateOfDeposited] => 24-Mar-2016
[challaNumber] => 999
)
)
[Registration Fee] => Array
(
[0] => Array
(
[LedgerID] => 5739b50b6e3dce450e8b4567
[LedgerName] => Registration Fee
[PanITNO] => ITR00123
[dateOfPayment] => 02-Jan-2016
[totalAmountPaid] => 1000
[tdsRate] => 10
[totalDudections] => 100
)
)
[Purchase1] => Array
(
[0] => Array
(
[LedgerID] => 573c321e6e3dcec3228b4567
[LedgerName] => Purchase1
[PanITNO] => ITR00123
[dateOfPayment] => 02-Jan-2016
[totalAmountPaid] => 8000
[tdsRate] => 2
[totalDudections] => 160
)
)
)
请建议是否可以使用任何PHP内置函数来执行此操作。
答案 0 :(得分:0)
试试这段代码。要连接数组,$arr1+$arr2
将起作用。但它不适用于您的情况。 Array_merge,递归合并和组合它们都不适合你的情况。因此,尝试使用for循环来合并它们。
foreach ($arr1 as $key1 => $value1) {
if($key1 == 'Development Fund') {
foreach($arr2['Development Fund'] as $key2 => $value2){
array_push($arr1['Development Fund'][$key2],$value2);
}
}
}
但这会给你这样的结果
Array
(
[Development Fund] => Array
(
[0] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 01-Dec-2015
[totalAmountPaid] => 49000
[tdsRate] => 2
[totalDudections] => 980
[0] => Array
(
[Amountdeposited] => 1000
[dateOfDeposited] => 01-Jan-2016
[challaNumber] => 2
)
)
[1] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 01-Mar-2016
[totalAmountPaid] => 4000
[tdsRate] => 2
[totalDudections] => 80
[0] => Array
(
[Amountdeposited] => 50000000
[dateOfDeposited] => 03-Mar-2016
[challaNumber] => 5555
)
)
[2] => Array
(
[LedgerID] => 573befb96e3dceb6468b4567
[LedgerName] => Development Fund
[PanITNO] => UK07AK1787
[dateOfPayment] => 23-Mar-2016
[totalAmountPaid] => 19000
[tdsRate] => 2
[totalDudections] => 380
[0] => Array
(
[Amountdeposited] => 90000
[dateOfDeposited] => 24-Mar-2016
[challaNumber] => 999
)
)
)
[Registration Fee] => Array
(
[0] => Array
(
[LedgerID] => 5739b50b6e3dce450e8b4567
[LedgerName] => Registration Fee
[PanITNO] => ITR00123
[dateOfPayment] => 02-Jan-2016
[totalAmountPaid] => 1000
[tdsRate] => 10
[totalDudections] => 100
)
)
[Purchase1] => Array
(
[0] => Array
(
[LedgerID] => 573c321e6e3dcec3228b4567
[LedgerName] => Purchase1
[PanITNO] => ITR00123
[dateOfPayment] => 02-Jan-2016
[totalAmountPaid] => 8000
[tdsRate] => 2
[totalDudections] => 160
)
)
)
你可以吗?
答案 1 :(得分:0)
function MergMultiDmsAry($array1,$array2)
{
$i = 0;
$newa = array();
$god = array();
$final = array();
foreach($array1 as $key=>$value)
{
for($j = 0; $j < count($value); $j++)
{
$newa = array_merge($value[$j],$array2[$key][$j]);
$god[] = $newa;
}
$i++;
// set the key
$final[$key] = $god;
}
print_r($final);
}
$data = array('dev'=>array(array('id'=>1),array('id'=>2)));
$data2 = array('dev'=>array(array('name'=>'john','address'=>'damak'),array('name'=>'mayer','address'=>'kathmandu')));
MergMultiDmsAry($data,$data2);
这可能会对你有所帮助
答案 2 :(得分:0)
给我回答:
Array ( [dev] => Array
( [0] =>
Array ( [id] => 1 [name] => john [address] => damak )
[1] =>
Array ( [id] => 2 [name] => mayer [address] => kathmandu )
) )