PHP code example of spaf / count-y

1. Go to this page and download the library: Download spaf/count-y library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spaf / count-y example snippets




use spaf\county\Counter;
use spaf\county\storage\StorageFile;
use spaf\simputils\PHP;

PHP::init();

$c = new Counter(new StorageFile());
//  In case if the StorageFile is not specified, the value will be stored in memory (StorageMemory
//  class). So it will exist until end of the runtime/execution.
//$c = new Counter();

//  If you need events, first delegate/closure is an event function, the second - event condition. The first will work,
//  only if the second will return TRUE, or if condition delegate/closure is not specified.

//$c->add_event('My first test event', function ($value, $name) {
//	echo "EVENT of {$name} for value of {$value}\n";
//}, fn($v) => $v % 10 == 0 );

for ($i = 0; $i <= 105; $i++) {
	$c->visit();
	$c->visit();
	$c->visit();
}

echo "Test: {$c}";