Skip to content

Instantly share code, notes, and snippets.

@firomero
Created August 28, 2015 12:49
Show Gist options
  • Save firomero/d34035d15130d685fe07 to your computer and use it in GitHub Desktop.
Save firomero/d34035d15130d685fe07 to your computer and use it in GitHub Desktop.
Array unique in Objects
/**
* Array unique in object
* @param $obj
* @return mixed
*/
function object_unique($obj)
{
$objArray = (array)$obj;
$objArray = array_intersect_assoc(array_unique($objArray), $objArray);
foreach ($obj as $n => $f) {
if (!array_key_exists($n, $objArray)) unset($obj->$n);
}
return $obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment