note 108421 added to function.array-unique
| From: | sashasimkin at gmail dot com | Date: | Wed, 25 Apr 2012 13:26:30 +0000 |
| Subject: | note 108421 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187336@lists.php.net to get a copy of this message | ||
My object unique function:
<?php
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;
}
?>
And these code:
<?php
class Test{
public $pr0 = 'string';
public $pr1 = 'string1';
public $pr2 = 'string';
public $pr3 = 'string2';
}
$obj = new Test;
var_dump( object_unique( $obj ) );
?>
returns:
object(Test)[1]
public 'pr0' => string 'string' (length=6)
public 'pr1' => string 'string1' (length=7)
public 'pr3' => string 'string2' (length=7)
----
Server IP: 69.147.83.197
Probable Submitter: 92.113.54.87
----
Manual Page -- http://www.php.net/manual/en/function.array-unique.php
Edit -- https://master.php.net/note/edit/108421
Del: integrated -- https://master.php.net/note/delete/108421/integrated
Del: useless -- https://master.php.net/note/delete/108421/useless
Del: bad code -- https://master.php.net/note/delete/108421/bad+code
Del: spam -- https://master.php.net/note/delete/108421/spam
Del: non-english -- https://master.php.net/note/delete/108421/non-english
Del: in docs -- https://master.php.net/note/delete/108421/in+docs
Del: other reasons-- https://master.php.net/note/delete/108421
Reject -- https://master.php.net/note/reject/108421
Search -- https://master.php.net/manage/user-notes.php