note 101390 deleted from class.splmaxheap by danbrown

From: Date: Tue, 14 Dec 2010 15:26:18 +0000
Subject: note 101390 deleted from class.splmaxheap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174906@lists.php.net to get a copy of this message
Note Submitter: MuLoT ---- <?php // File Heap with max size on top class UserFiles extends SplMaxHeap { public function compare( SplFileInfo $value1, SplFileInfo $value2 ) { return ( $value1->getSize() - $value2->getSize() ); } } $obj = new UserFiles(); $obj->insert( new SplFileInfo( 'path/to/my/file/1' ) ); // 3.9 Mo $obj->insert( new SplFileInfo( 'path/to/my/file/2' ) ); // 9.8 Mo $obj->insert( new SplFileInfo( 'path/to/my/file/3' ) ); // 0.8 Mo $obj->insert( new SplFileInfo( 'path/to/my/file/4' ) ); // 16 Mo foreach( $obj as $file ) { echo $file->getPathname()."\n"; } /* Output display : path/to/my/file/4 path/to/my/file/2 path/to/my/file/1 path/to/my/file/3 */ ?>

« previous php.notes (#174906) next »