-1

array1:

Array ( 
    [0] => Array ( 
        [name] => January 
        [scale_of_pay] => 7800-39000 
        [pay] => 25000 
        [grade_pay] => 5000 
        [d_a] => 5000 
        [h_r_a] => 5000 
        [t_a] => 1000 
        [other] => 5000 
        [net_claim] => 46000 
    )

array2:

Array ( 
    [0] => Array ( 
        [national_two_bank] => 700 
        [bhgylaxshmi_banks] => 1000 
        [maheshwari_bank] => 1000 
        [maha_bank] => 1000 
        [mahesh_cooperative_bank] => 1000 
        [co_operative] => 1000 
        [lic] => 1000 
        [total_deduction] => 6700 
    ) 

want answer like :

Array ( 
    [0] => Array ( 
        [name] => January 
        [scale_of_pay] => 7800-39000 
        [pay] => 25000 
        [grade_pay] => 5000 
        [d_a] => 5000 
        [h_r_a] => 5000 
        [t_a] => 1000 
        [other] => 5000 
        [net_claim] => 46000 
        [national_two_bank] => 700 
        [bhgylaxshmi_banks] => 1000 
        [maheshwari_bank] => 1000 
        [maha_bank] => 1000 
        [mahesh_cooperative_bank] => 1000 
        [co_operative] => 1000 
        [lic] => 1000 
        [total_deduction] => 6700
    )

when i merger array using array_merge answer is like,

Array(
    [0] => Array(
        [name] => January[scale_of_pay] => 7800 - 39000[pay] => 25000[grade_pay] => 5000[d_a] => 5000[h_r_a] => 5000[t_a] => 1000[other] => 5000[net_claim] => 46000
    ) [1] => Array(
        [name] => February[scale_of_pay] => 7800 - 39000[pay] => 25000[grade_pay] => 5000[d_a] => 5000[h_r_a] => 5000[t_a] => 1000[other] => 5000[net_claim] => 46000
    ) [2] => Array(
        [name] => March[scale_of_pay] => 7800 - 39000[pay] => 25000[grade_pay] => 5000[d_a] => 5000[h_r_a] => 5000[t_a] => 5000[other] => 5000[net_claim] => 50000
    ) [3] => Array(
        [national_two_bank] => 700[bhgylaxshmi_banks] => 1000[maheshwari_bank] => 1000[maha_bank] => 1000[mahesh_cooperative_bank] => 1000[co_operative] => 1000[lic] => 1000[total_deduction] => 6700
    ) [4] => Array(
        [national_two_bank] => 1000[bhgylaxshmi_banks] => 1000[maheshwari_bank] => 1000[maha_bank] => 1000[mahesh_cooperative_bank] => 1000[co_operative] => 1000[lic] => 1000[total_deduction] => 7000
    ) [5] => Array(
        [national_two_bank] => 1000[bhgylaxshmi_banks] => 1000[maheshwari_bank] => 1000[maha_bank] => 1000[mahesh_cooperative_bank] => 1000[co_operative] => 1000[lic] => 1000[total_deduction] => 7000
    )
)

i dont wants like this...

jlocker
  • 1,478
  • 1
  • 12
  • 23
dharmx
  • 694
  • 1
  • 13
  • 20

2 Answers2

0

You want to use the array_merge function. In your specific example it would be as easy as array_merge($array1[0], $array2[0])

Here is an example

<?php
    $array1 = array( array( 'test' => 'testing1', 'test2' => 'testing2' ) );
    $array2 = array( array( 'test3' => 'testing3', 'test4' => 'testing4' ) );
    print_r( array_merge( $array1[0], $array2[0] ) );
?>

This outputs

Array ( [test] => testing1 [test2] => testing2 [test3] => testing3 [test4] => testing4 )

Jesse
  • 2,790
  • 1
  • 20
  • 36
  • this also works for me but array_map done all things because i have more than one values.... – dharmx Oct 19 '15 at 09:23
0

For a solution that works with arrays with more than one inner value, try :

array_map('array_merge', $a1, $a2);

Here's an example https://repl.it/BRdQ

Francis Eytan Dortort
  • 1,407
  • 14
  • 20