1

我离这太近了,我只能尖叫。

这就是我所追求的。我有两个数组。第一个如下:

array("id", "txtLname", "txtFname");

第二种如下:

Array
(
    [0] => Array
        (
            [id] => 220
            [RecordGUID] => 1233C9-1F7A15-E8A447-C56CB2-227C20-2829E0
            [txtEmplid] => 5469857
            [txtLname] => Jones
            [txtFname] => Richard
            [txtMname] => 
            [txtEmail] => email address
            [Reg_Pass] => umbra1234
            [Reg_User] => user
            [txtSecEmail] => user@gmail.com
            [dtDOB] => 1979-02-28
            [drpStatus] => STUDENT
            [lstWaive] => 1
            [ENTERED] => 2013-09-15 18:03:18
            [Status] => 0
            [Approvalcode] => 17dc8e7336f0e9fd3411a4d9617efe865c5744ac
            [Approvaldate] => 2013-09-15 18:03:47
            [Approved] => 1
        )

    [1] => Array
        (
            [id] => 221
            [RecordGUID] => DD1E72-368879-68CFE2-E03010-ECE1B1-0974E9
            [txtEmplid] => 4454688
            [txtLname] => Mathews
            [txtFname] => Richard
            [txtMname] => 
            [txtEmail] => user2@gmail.com
            [Reg_Pass] => umbra1234
            [Reg_User] => user
            [txtSecEmail] => user3@gmail.com
            [dtDOB] => 1979-02-28
            [drpStatus] => STUDENT
            [lstWaive] => 1
            [ENTERED] => 2013-09-16 12:28:08
            [Status] => 0
            [Approvalcode] => 7182769e45dc38a3a747c4bdb128e2f0a8c658e4
            [Approvaldate] => 
            [Approved] => 0
        )

    [2] => Array
        (
            [id] => 222
            [RecordGUID] => 40D8E7-04C600-30A829-8E26CC-498BBE-9D3DF6
            [txtEmplid] => 
            [txtLname] => 
            [txtFname] => 
            [txtMname] => 
            [txtEmail] => 
            [Reg_Pass] => 
            [Reg_User] => 
            [txtSecEmail] => 
            [dtDOB] => 1979-02-28
            [drpStatus] => STUDENT
            [lstWaive] => 1
            [ENTERED] => 2013-09-16 12:28:24
            [Status] => 0
            [Approvalcode] => 8d2c33f7b7d6ef620811dbc4358e8103346bfb59
            [Approvaldate] => 
            [Approved] => 0
        )

)

我只需要遍历第二个数组并删除与第一个不匹配的项目。结果如下:

Array
(
    [0] => Array
        (
            [id] => 220
            [txtLname] => Method
            [txtFname] => Richard

        )

    [1] => Array
        (
            [id] => 221
            [txtLname] => Method
            [txtFname] => Richard

        )

    [2] => Array
        (
            [id] => 222
            [txtLname] => Method
            [txtFname] => Richard

        )

)

这是我到目前为止所做的。

foreach ($r as $reg) {
foreach($reg as $k => $v) {
    if ($k == !in_array($k, $f)) {
        echo $reg[$k];
    }
}

}

我得到的回声响应是第一个数组中所有数据的列表,减去第一个数组中的字段。因此,它正在删除我想要删除的项目,但我似乎无法将其转换为正确的格式。

在此先感谢您的帮助。

4

2 回答 2

1

替换echo $reg[$k];unset($reg[$k]);

于 2013-09-16T21:14:53.250 回答
1
$arr1 = array("id"=>1, "txtLname"=>1, "txtFname"=>1)
$result = array();

// $arr2 = array 2 (check your code)


foreach ($arr2 as $el) {
   $result[] = array_intersect_key($el, $arr1);
}

var_dump($result);
于 2013-09-16T21:25:40.050 回答