Webbserverprogrammering 1

Källkod

Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.

webbserverprogrammering/exercises/classes_dice/

10 filer

Dice.php
DiceImage.php
Histogram.php
dice_1.php
dice_2.php
dice_3.php
dice_4.php
dice_5.php
dice_6.php
dice_7.php

Histogram.php

38 lines UTF-8 Windows (CRLF)
<?php
 
class Histogram {
  function 
__construct() {
   
// echo "Histogram skapat!";
   // echo __METHOD__;
  
}

  function 
__destruct() {
   
// echo "Histogram förstört!";
   // echo __METHOD__;
  
}

  static function 
getHistogram($values$max 0) {
   
$assocArray = [];

   if (
max($values) > $max)
    
$max max($values);

   for (
$i 1$i <= $max$i++) {
    
$assocArray["$i"] = 0;
   }

   for (
$i 0$i count($values); $i++) { 
    
$assocArray["$values[$i]"]++;
   }

   echo 
"<div id='histogram'><h5>Histogram</h5>";
   foreach (
$assocArray as $value => $occurrences) {
    echo 
str_replace('~''&nbsp;'str_pad("$value"2"~"STR_PAD_LEFT)) . " | ";
    for (
$i 0$i $occurrences$i++) { 
     echo 
"█";
    }
    echo 
"<br>";
   }
   echo 
"</div>";
  }
 }
?>