maexus Posted September 12, 2007 Share Posted September 12, 2007 $foos = simplexml_load_file("bar.xml"); Lets say bar.xml has 50 entries and lets say 25-50% of those are duplicates. How would I get rid of those. Here is how I'm using it foreach($foos as $foo){ echo $foo->entry; } I don't think that $foos or $foos->entry is an array so array_unique won't work. Help? Quote Link to comment https://forums.phpfreaks.com/topic/68961-remove-duplicate-items-from-a-simplexml-object/ Share on other sites More sharing options...
kireol Posted September 12, 2007 Share Posted September 12, 2007 hrmmm. maybe convert it to an array? I could be wrong. function object2array($object) { $return = NULL; if(is_array($object)) { foreach($object as $key => $value) $return[$key] = object2array($value); } else { $var = get_object_vars($object); if($var) { foreach($var as $key => $value) $return[$key] = object2array($value); } else return strval($object); // strval and everything is fine } return $return; } Quote Link to comment https://forums.phpfreaks.com/topic/68961-remove-duplicate-items-from-a-simplexml-object/#findComment-346626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.