3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $obj1 = new stdClass(); $obj1->attr = 'Rod'; $obj2 = new stdClass(); $obj2->attr = 'Jane'; $obj3 = new stdClass(); $obj3->attr = 'Freddy'; $array1 = array( $obj1, $obj2, ); $array2 = array( $obj1, $obj3, ); $diff1 = array_udiff($array1, $array2, function($a,$b) { if ($a->attr == $b->attr) { return 0; } else { return -1; } }); $diff2 = array_udiff($array1, $array2, function($a,$b) { if ($a->attr == $b->attr) { return 0; } else { return 1; } }); var_dump($diff1); var_dump($diff2);
based on KHlAt
Output for 7.0.0 - 7.2.0
array(1) { [1]=> object(stdClass)#2 (1) { ["attr"]=> string(4) "Jane" } } array(2) { [0]=> object(stdClass)#1 (1) { ["attr"]=> string(3) "Rod" } [1]=> object(stdClass)#2 (1) { ["attr"]=> string(4) "Jane" } }
Output for 5.3.19 - 5.6.28
array(2) { [0]=> object(stdClass)#1 (1) { ["attr"]=> string(3) "Rod" } [1]=> object(stdClass)#2 (1) { ["attr"]=> string(4) "Jane" } } array(1) { [1]=> object(stdClass)#2 (1) { ["attr"]=> string(4) "Jane" } }