PHP code example of devlop / buffer

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

    

devlop / buffer example snippets


use Devlop\Buffer\Buffer;

$bigFuckingArray = [...]; // array containing between zero and many many items

$buffer = new Buffer(
    10, // max Buffer size
    function (array $items) : void {
        // callback to apply when buffer size reaches max
    },
);

foreach ($bigFuckingArray as $key => $value) {
    $buffer->push($value); // the Buffer callback will automatically be applied when needed
}

// important, after looping over the array, remember to manually call the flush() method to apply the callback on last time if needed
$buffer->flush();

use Devlop\Buffer\Buffer;

$bigFuckingArray = [...]; // array containing between zero and many many items

Buffer::iterate(
    $bigFuckingArray, // input iterable
    10, // max Buffer size
    function (array $items) : void {
        // callback to apply when buffer size reaches max
        // the callback will also be called one last time after finishing iterating if needed
    },
)