Show sourcecode
The following files exists in this folder. Click to view.
webbserv1-dice/exercises/dice4/
CDice.php
CHistogram.php
dice-4.php
CHistogram.php
43 lines ASCII Unix (LF)
<?php
/**
* A class for printing a histogram.
*
*/
class CHistogram {
/**
* Properties
*
*/
/**
* Print the histogram
*
* @param array $values the values to print out the histogram from.
*/
public function GetHistogram($values) {
// Calculate occurences for each key
$res = array();
for ($i=1;$i<7;$i++) $res[$i]=0;
foreach($values as $value) {
$res[$value]++;
}
// Prepare out a textual representation of the histogram
$html = "<ol>";
foreach($res as $rvalue) {
$html .= "<li>";
for ($i=1;$i<=$rvalue;$i++) {
$html .= "*";
}
$html .= " ($rvalue st)</li>";
}
$html .= "</ol>";
return $html;
}
}
