PHP按键将数组合并为多维数组

时间:2014-10-15 20:00:35

标签: php multidimensional-array merge

这是我的阵列:

$recid[$row['Rec_Mgmt_id']] = array
(
    'program'=> $row['Program'],
    'doc' => $row['Date_of_clinic'],
    'name' => $row["FName"]. " " . $row['LName'],
    'claim' => $row['ClaimNum'],
    'md' => $row['Doctor'],
    'prognosis' => $row['Prognosis'],
    'workStatus' => $row['WorkStatus'],
    'service' => array
    (
        $row['Service_Requested_id'] => array
        (
            'name' => $row['Service'], 
            'site' => $row['Service_Site'], 
            'status' => $row['Approval_Status'], 
            'denial' => $row['Reason_Denial'], 
            'approvalDate' => $row['Date_Approval'], 
            'txIn' => $row['TX_Intake_Date'], 
            'txOut' => $row['TX_Discharge_Date'], 
            'comments' => $row['Comments']
        )
    )
);

如何将以下数组添加为另一项服务'阵列

array($row['Service_Requested_id'] => array
    (
    'name' => $row['Service'], 
    'site' => $row['Service_Site'], 
    'status' => $row['Approval_Status'], 
    'denial' => $row['Reason_Denial'], 
    'approvalDate' => $row['Date_Approval'], 
    'txIn' => $row['TX_Intake_Date'], 
    'txOut' => $row['TX_Discharge_Date'], 
    'comments' => $row['Comments']
    )
);

也许是因为我感觉脑部有点死...但我尝试了很多方法而且我无法将其添加。

1 个答案:

答案 0 :(得分:1)

我不确定我完全理解你的问题,但我认为这会做你需要的。

$recid[$row['Rec_Mgmt_id']]['service'][$row['Service_Requested_id']] = array (      
     'name' => $row['Service'], 
     'site' => $row['Service_Site'], 
     'status' => $row['Approval_Status'], 
     'denial' => $row['Reason_Denial'], 
     'approvalDate' => $row['Date_Approval'], 
     'txIn' => $row['TX_Intake_Date'], 
     'txOut' => $row['TX_Discharge_Date'], 
     'comments' => $row['Comments']);