I have arrays containing objects that look like the following, first array:

Array ( [1] => stdClass Object ( [matchID] => 1 [tm] => 2014-01-16 08:55:13 [playertm] => 2014-01-16 08:55:14 ) [2] => stdClass Object ( [matchID] => 2 [tm] => 2014-01-16 09:53:50 [playertm] => 2014-01-16 09:53:52 ) [3] => stdClass Object ( [matchID] => 3 [tm] => 2014-01-16 09:58:49 [playertm] => 2014-01-16 09:58:57 ) [4] => stdClass Object ( [matchID] => 4 [tm] => 2014-01-17 08:44:34 [playertm] => 2014-01-17 08:44:35 ) )

Second array:

Array ( [3] => stdClass Object ( [matchID] => 3 [tm] => 2014-01-16 09:58:49 [playertm] => 2014-01-16 09:58:57 ) [4] => stdClass Object ( [matchID] => 4 [tm] => 2014-01-17 08:44:34 [playertm] => 2014-01-17 08:44:38 ) [5] => stdClass Object ( [matchID] => 5 [tm] => 2014-01-19 08:44:34 [playertm] => 2014-01-19 08:44:38 ) )

And am trying to synchronize each array based on the times. I want 4 results to be returned:

The objects in the first array that have a time more recent than the second array The objects in the second array that have a time more recent than the first array The objects in the first array that have a 'playertm' more recent than the second array The objects in the second array that have a 'playertm' more recent than the first array

Some results may not be in each array and will need to be returned, however the array keys will always match.

I am using the 'array_udiff' function and so far have the following:

function tmCompare($a, $b) { return strtotime($a->tm) - strtotime($b->tm); } function ptmCompare($a, $b) { return strtotime($a->playertm) - strtotime($b->playertm); } $df1 = array_udiff($a, $b, 'tmCompare'); $df2 = array_udiff($b, $a, 'tmCompare'); $df3 = array_udiff($a, $b, 'ptmCompare'); $df4 = array_udiff($b, $a, 'ptmCompare');

Which appears to return the differences, however array [4] is returned in each of the last 2 functions, whereas I only want it to be returned if the time is larger rather than only different.

I have tried

return (strtotime($a->playertm) > strtotime($b->playertm)) ? -1 : 0;

and similar but cannot seem to get the correct results. Am I missing something simple here or going about this wrong?

Edit: here is a quick pastebin to get the code running http://pastebin.com/gRz9v2kz

Thanks for any help.