note 112712 added to language.oop5.basic

From: Date: Tue, 16 Jul 2013 02:43:38 +0000
Subject: note 112712 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-195637@lists.php.net to get a copy of this message
// Use this class to find frequency of words in a file class WordCounter { const ASC = 1; const DESC = 2; private $words; function __construct( $filename ) { $file_content = file_get_contents($filename); $this->words = array_count_values( str_word_count( strtolower($file_content) , 1 ) ); } // Use self inside class to access static , property , method although not mandatory, you can also use className public function count( $order ) { if( $order == self::ASC ) { asort($this->words); } else if( $order == self::DESC ) { arsort($this->words); } foreach( $this->words as $key => $value ) { echo $key . " = " . $value ."<br>"; } } } // End of class WordCounter $wc = new WordCounter("yourFileName.txt"); $wc->count( WordCounter::DESC); ---- Server IP: 69.147.83.199 Probable Submitter: 112.196.185.68 ---- Manual Page -- http://php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/112712 Del: integrated -- https://master.php.net/note/delete/112712/integrated Del: useless -- https://master.php.net/note/delete/112712/useless Del: bad code -- https://master.php.net/note/delete/112712/bad+code Del: spam -- https://master.php.net/note/delete/112712/spam Del: non-english -- https://master.php.net/note/delete/112712/non-english Del: in docs -- https://master.php.net/note/delete/112712/in+docs Del: other reasons-- https://master.php.net/note/delete/112712 Reject -- https://master.php.net/note/reject/112712 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195637) next »