两个多维数组之间的值替换


Array1
    (
        [0] => Array
            (
                [accNo] => 000000
                [accTypeCode] => C
                [accName] => something
                [accCurrency] => BDT
                [branchCode] => 101
                [branchName] => empty
            )
        [1] => Array
            (
                [accNo] => 0000
                [accTypeCode] => C
                [accName] => something
                [accCurrency] => BDT
                [branchCode] => 101
                [branchName] => empty
            )
        [2] => Array
            (
                [accNo] => 0000
                [accTypeCode] => L
                [accName] => something
                [accCurrency] => BDT
                [branchCode] => 999
                [branchName] => empty
            )
        [3] => Array
            (
                [accNo] => 00000
                [accTypeCode] => L
                [accName] => something
                [accCurrency] => BDT
                [branchCode] => 999
                [branchName] => empty
            )
    )


Array2
    (
        [0] => Array
            (
                [branchCode] => 101
                [ATMName] => Agrabad
            )
        [1] => Array
            (
                [branchCode] => 999
                [ATMName] => Azimpur
            )
    )

这是我的两个数组array1和array2。现在我需要做的是,在array1中,branchCode为101,branchName empty将被array2的ATMName取代,其中branchCode为101,999也是如此。

还没有试过,但大多数情况下应该可以。

for($c1=0;$c1<count($array1);$c1++)
{
    if($array1[$c1]['branchName']=="empty")
    {
          for($c2=0;$c2<count($array2);$c2++)
          {
               if($array1[$c1]['branchCode']==$array2[$c2]['branchCode'])
               {
                    $array1[$c1]['branchName']=$array2[$c2]['ATMName'];            
               }
          }
    }
}

一定要让我知道它是否有效!

相关内容

  • 没有找到相关文章

最新更新