<?
/*
  Beer Counter:
    Display important information about beer consumption.

     - http://prague.tv/toys/beer/

  author: Peter Lowe (peter@prague.tv / pgl@yoyo.org)
*/

function beer_stats($litresofbeer$numpeople$timestamp='') {
    
// this function could be written a lot more concisely.

    
if (!$timestamp)
        
$timestamp    time();

    
$numseconds        $timestamp mktime(00011);

    
$litrespersecond    $litresofbeer / (365 24 3600);
    
$beersdrunksofar    $numseconds $litrespersecond;
    
$litresperheadsofar    $beersdrunksofar $numpeople;
    
$hourlyrate        $litrespersecond 3600;

    
$round  create_function('$num''return round($num, 2);');

    return 
array_map($round, array(
        
'litres per second'        => $litrespersecond,
        
'beers drunk so far'        => $beersdrunksofar,
        
'litres per head so far'    => $litresperheadsofar,
        
'hourly rate'            => $hourlyrate,
        ));
    }

$czech_population    10.26 pow(106);    // source: http://www.cia.gov/cia/publications/factbook/geos/ez.html
$czech_yearly_total    17.8 pow(106);    // source: http://www.duvel.be/uk/Investor2.htm

$beerstats beer_stats($czech_yearly_total$czech_population);
?>
<table cellpadding=7 cellspacing=1 bgcolor="#444444" width="100%">
<tr bgcolor=white><td>

<br><br>
<center><b><?=number_format($beerstats['beers drunk so far'])?> litres of beer</b></center>

<br><br>
That's an average of <?=$beerstats['hourly rate']?> per hour or <?=$beerstats['litres per second']?> per second, with every man, woman, and child each having drunk <?=$beerstats['litres per head so far']?> litres.

</td></tr>

</table>