2

現在、2 つの配列があります。2 つの配列の違いを取得するにはどうすればよいですか?

foreach($test1 as $array)
{
    if (!isset($result[$array["id"]])) $result[$array["id"]] = $array["date"];
}
foreach ($result as $id => $date) {
    $new1[] = array("id" => $id, "date" => $date);
}

この出力が得られます:

Array ( [0] => Array ( [id] => 47523 [date] => 11-02-13 05:36:32 ) [1] => Array ( [id] => 42415 [date] => 12-02-13 13:56:48 ) 

_

foreach($test2 as $array) {
    if (!isset($result[$array["id"]])) $result[$array["id"]] = $array["date"];
}
foreach ($result as $id => $date) {
    $new2[] = array("id" => $id, "date" => $date);
}

この出力が得られます:

Array ( [0] => Array ( [id] => 47523 [date] => 12-02-13 14:22:14 ) [1] => Array ( [id] => 42135[date] => 02-02-13 14:51:42 ) 

今、私は違いを得ることができるようにそれらを比較したい:私は期待される出力が次のようになることを望みます:

Array ( [0] => Array ( [id] => 42415 [date] => 12-02-13 13:56:48 ) [1] => Array ( [id] => 42135[date] => 02-02-13 14:51:42) 
4

1 に答える 1

0

使用するarray_diff()

<?php
$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);

print_r($result);
?>

Array
(
    [1] => blue
)
于 2013-02-12T14:12:46.527 に答える