PHP code example of shiyan / iterate

1. Go to this page and download the library: Download shiyan/iterate 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/ */

    

shiyan / iterate example snippets


use Shiyan\Iterate\Scenario\BaseRegexScenario;

class ExampleScenario extends BaseRegexScenario {

  const PATTERN_EMPTY = '/^$/';
  const PATTERN_PHP = '/PHP/';

  public $counter;

  public function getPatterns(): array {
    return [self::PATTERN_EMPTY, self::PATTERN_PHP];
  }

  public function preRun(): void {
    $this->counter = 0;
  }

  public function onMatch(array $matches, string $pattern): void {
    switch ($pattern) {
      case self::PATTERN_EMPTY:
        $this->iterator[$this->iterator->key()] = 0;
        break;

      case self::PATTERN_PHP:
        print $this->iterator->current() . "\n";
        break;
    }
  }

  public function ifNotMatched(): void {
    ++$this->counter;
  }

}