PHP code example of konfirm / collection

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

    

konfirm / collection example snippets




use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c', 'b', 'a');
$unique = $provider->unique();
//  'a', 'b', 'c'



use Konfirm\Collection\Provider;

$first = new Provider('a', 'b', 'c', 'b', 'a');
$second = new Provider('foo', 'bar', 'c', 'b');

$common = $first->intersect($second);
//  'b', 'c', 'b';



use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c', 'b', 'a');
$filtered = $provider->filter(function($value, $index /*, $provider*/) {
	return $value !== 'a' && $index % 2 === 0;
});
// 'c'



use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c', 'b', 'a');
$mapped = $provider->map(function($value /*, $index, $provider*/) {
	return sprintf('*%s*');
});
// '*a*', '*b*', '*c*', '*b*', '*a*'   



use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c');
$reduce = $provider->map(function($carry, $value, $index) {
	return $carry + $value;
});
// 'abc'   



use Konfirm\Collection\Provider;

$provider = new Provider('a', 'b', 'c');
$reduce = $provider->map(function($carry, $value, $index) {
	return $carry + $value;
}, 'my result: ');
// 'my result: abc'