how to sort collection of objects in php -
please me sort such type of collection in php, below collection of objects has sort in desecnding order.
$og = stdclass object ( [datanumen[dot]com] => 10 [diskinternals[dot]com] => 1 [download[dot]cnet[dot]com] => 2 [easeus[dot]com] => 5 [en[dot]pstrecovery[dot]net] => 6 [en[dot]pstrecovery[dot]org] => 3 [howto-outlook[dot]com] => 4 [kerneldatarecovery[dot]com] => 2 [mail2web[dot]com] => 2 [msoutlook[dot]info] => 4 [nirsoft[dot]net] => 1 [office[dot]microsoft[dot]com] => 14 [officerecovery[dot]com] => 1 [outlook[dot]recoverytoolbox[dot]com] => 1 [outlookpstrecovery[dot]com] => 16 [outlookrecovery-tool[dot]com] => 1 [outlookrecovery[dot]net] => 1 [pst-repair-tool-free[dot]software[dot]informer[dot]com] => 1 [pstrepair[dot]net] => 1 [pstrepairutility[dot]net] => 9 [pstscanner[dot]com] => 11 [recovermyemail[dot]com] => 2 [slipstick[dot]com] => 4 [social[dot]technet[dot]microsoft[dot]com] => 2 [stellarinfo[dot]com] => 14 [support[dot]microsoft[dot]com] => 15 [techrepublic[dot]com] => 17 )
please me sort such type of collection in php
this easy if temporarily convert array:
$og = (array) $og; asort( $og ); $og = (object) $og;
as example:
$og = new stdclass; $og->a = 5; $og->b = 2; $og->c = 8; $og->d = 1; $og = (array) $og; asort( $og ); $og = (object) $og; echo '<pre>'; print_r( $og ); echo '</pre>';
Comments
Post a Comment