Php i';我对如何在foreach循环中使用数组合并感到困惑

Php i';我对如何在foreach循环中使用数组合并感到困惑,php,sql,foreach,array-merge,Php,Sql,Foreach,Array Merge,以下是我的功能: function addr($dfcode) { return sql::results("select A.CODE_, case when b.id is null then a.ADDRESS1 else b.addr1 as Address1, case when b.id is null then a.ADDRESS2 else b.addr2 as A

以下是我的功能:

function addr($dfcode)
        {
        return sql::results("select
              A.CODE_,
              case when b.id is null then a.ADDRESS1 else b.addr1 as Address1,
              case when b.id is null then a.ADDRESS2 else b.addr2 as Address2,
              case when b.id is null then a.CITY else b.city as City,
              case when b.id is null then a.STATE_ else b.state as State,
              case when b.id is null then a.ZIP else b.zip as Zip,
              case when b.id is null then a.PHONE else b.phone as Phone,
              case when b.id is null then a.FAX else b.fax as Fax
        from ARE.ADS.DFE a
        left outer join (
              select
                    *
              from ent.dbo.patient_data a
              inner join ent.dbo.doctor_alt_address b on a.doctor_address_id = b.id
              where a.CODE_ =" . $this->patient->hex . "
              and b.doctor_id =" . hexstr($dfcode) . "
              )b on a.CODE_ = b.doctor_id
        where a.CODE_=" . hexstr($dfcode));
        }
我需要将上述函数合并到foreach循环中。我不确定如何做到这一点,我对array_merge真的是个新手。在下面,我提取了构建表单所需的所有医生信息

上述情况下,医生有一个备用地址,如果在数组合并中a.doctor\u address\u id=上述条件中的b.id,则需要使用该地址

$p->customForm()->log_creation($docname);   

$doctor = new \CRM\Doctor($p->customForm()->dfcode($docname));

foreach ($doctor->getVars() as $k => $v)
    {
    $data['doctor_'. $k] = $v;
    }

foreach ($patient->get_data() as $k=>$v)
    {
    if (is_string($v) || is_numeric($v))
        $data["patient_" . $k] = strtoupper($v);
    }
我希望这不会让人困惑,任何帮助都将不胜感激。我希望也不要含糊不清。多谢各位

$data的var_转储

Array
(
    [employee] => person
    [date] => 05/08/2013
    [datetime] => 05/08/2013 9:41:15 AM
    [department] => stuff
    [employee_ext] => 7457
    [employee_email] => 
    [barcode] => *NZS01*
    [doctor_df_code] => 09HQ
    [doctor_npi] => 1111111111
    [doctor_dea] => B4574
    [doctor_upin] => 
    [doctor_license] => 
    [doctor_phone] => (111)111-1111
    [doctor_fax] => (000)000-0000
    [doctor_fname] => UNDEFINED
    [doctor_lname] => UNDEFINED
    [doctor_title] => 
    [doctor_intake_rx_caller_id] => 
    [doctor_costco_rx_caller_id] => 
    [doctor_reorder_rx_caller_id] => 
    [doctor_address1] => 24 CABELL st
    [doctor_address2] => SUITE 10
    [doctor_city] => places
    [doctor_state] => CA
    [doctor_zip] => 91111
    [doctor_active_events] => 
    [doctor_dont_call] => 0
    [doctor_dont_fax] => 1
)
下面是addr()的print变量


如果有一个备用地址,我需要用array merge addr()覆盖它。

那么您要在哪里进行array\u merge?在您的代码示例中,我根本看不到这一点。我也不知道第一个代码示例与第二个代码示例的关系如何。我想在$data之后对函数addr($dfcode)进行数组合并。那么问题是什么呢?尝试合并数组时会得到什么结果?你期望得到什么样的结果?实际上,在这种情况下,删除所有代码并显示您试图合并的数组的var_转储,以及您实际试图合并的代码将更加有用。我不确定如何将函数移动到循环中。我将发布我当前的var转储。@MikeBrant,用var\u转储更新
Array
(
    [0] => Array
        (
            [CODE_] => 09HQ
            [doctor_address1] => alternate addy
            [doctor_address2] => 45854
            [doctor_city] => different city
            [doctor_state] => CA
            [doctor_zip] => 963545
            [doctor_phone] => (619)111-2548
            [doctor_fax] => (157)123-4569
        )

)