2015-05-08 53 views
0

我正在查詢DB2平面文件和常規表以獲取信息。最新的數據將來自不平坦的文件。我將兩個結果放入兩個單獨的數組中。理想情況下,我認爲加入表格應該是最好的,但我試過了,我不知道你是否可以將平面文件加入非平面文件表格。這裏是陣列1如何「結合」數組

Array 
(
    [0] => Array 
     (
      [pEmpNum] => 450 
      [trCode] => 1 
      [pRate] => 40.00 
      [pWeeksWorked] => 2.00 
      [pAppr] => J014 1  
     ) 

) 

這是第二

1Array 
(
[12] => Array 
     (
      [empNum] => 160  
      [location] => 2   
      [payGroup] => 3 
      [weeksWorked] => 02 
      [defaultPay] => Y 
      [unitRate] => 75.00 
      [rate] => 18.67 
      [appFlag] => 
      [app1] => J014 1  
      [app2] => 
      [app3] => 
      [app4] => 
      [app5] => 
      [unit1] => .00 
      [unit2] => .00 
      [unit3] => .00 
      [unit4] => .00 
      [unit5] => .00 
      [gross] => 1400.25 
     ) 

    [13] => Array 
     (
      [empNum] => 450   
      [location] => 2 
      [payGroup] => 3 
      [weeksWorked] => 00 
      [defaultPay] => 
      [unitRate] => 0.00 
      [rate] => 24.63 
      [appFlag] => 
      [app1] => J014 1  
      [app2] => 
      [app3] => 
      [app4] => 
      [app5] => 
      [unit1] => .00 
      [unit2] => .00 
      [unit3] => .00 
      [unit4] => .00 
      [unit5] => .00 
      [gross] => 0.00 
     ) 

) 

我所試圖做的是,如果empnum第一陣列中存在我想從更換所有的信息的一部分array1並將其放入array2中以獲得相同的empnum。所以在這個例子中,因爲empnum 450存在於兩個數組中,所以我想用pRate替換unitRate,使用pWeeksWorked處理周,使用pAppr處理app1。任何幫助或更好的建議如何這將是很大的。

+0

數組有多大? –

+0

它們都會發生變化 – moe

+0

如果您的問題包含DB2的平臺和版本,這將有所幫助 – Charles

回答

0

這是我的建議。第二個是$array1,第一個是$array2。你通過它們循環,如果empnum匹配你交換相關的值。這是一個'純粹的'PHP解決方案。

foreach($array1 as $key1 => $data1) 
{ 
    foreach($array2 as $key2 => $data2) 
    { 
    if ($data1['pEmpNum'] == $data2['empNum']) 
    { 
     $data2['unitRate'] = $data1['pRate']; 
     $data2['weeksWorked'] = $data1['pWeeksWorked']; 
     $data2['app1'] = $data1['pAppr']; 
    } 
    } 
} 
+0

這個工作非常完美! – moe