PHP code example of meekframework / collection

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

    

meekframework / collection example snippets


$stack = new Meek\Collection\UnboundedStack();

$stack->push('1');  // All future push() operations will only accept the string data type.

$stack->push(2);    // Throws an InvalidArgumentException -> must be a string

class MyClass extends stdClass {}

$stack = new Meek\Collection\UnboundedStack();

$stack->push(new stdClass());   // All future push() operations will only accept instances of `stdClass`.
$stack->push(new MyClass());    // Works fine as `MyClass` is sub-classed from `stdClass`


$stack->push(new class {});    // Throws an InvalidArgumentException -> must be an instance of "stdClass"

$wordToReverse = 'dog';
$stack = new Meek\Collection\UnboundedStack(...str_split($wordToReverse));
$reversedWord = '';

while ($stack->size() > 0) {
    $reversedWord .= $stack->pop();
}

print $reversedWord;    // prints 'god'

$numberOfActionsToKeepTrackOf = 3;
$stack = new Meek\Collection\BoundedStack($numberOfActionsToKeepTrackOf);

$perform = function ($action) use ($stack) {
    $stack->push($action);
    echo sprintf('perform: %s', $action);
};

$undo = function () use ($stack) {
    $action = $stack->pop();
    echo sprintf('undo: %s', $action);
};

$perform('select all');     // prints 'perform: select all'
$perform('copy');           // prints 'perform: copy'
$perform('paste');          // prints 'perform: paste'
$undo();                    // prints 'undo: paste'
$perform('paste');          // prints 'perform: paste'

try {
    $perform('select all');
} catch (OverflowException $e) {
    // clear history and keep going or notify user that history is full
}