I have 2 arrays right now, how can i get the difference between 2 arrays?
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);
}
Gives me this output:
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);
}
Gives me this output:
Array ( [0] => Array ( [id] => 47523 [date] => 12-02-13 14:22:14 ) [1] => Array ( [id] => 42135[date] => 02-02-13 14:51:42 )
Now i want to compare them so i can get the difference out: I would like that the expected output as follows:
Array ( [0] => Array ( [id] => 42415 [date] => 12-02-13 13:56:48 ) [1] => Array ( [id] => 42135[date] => 02-02-13 14:51:42)
Use 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
)