PHP code example of pitchart / transformer

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

    

pitchart / transformer example snippets


use function Pitchart\transform;

transform([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
    ->filter(function (int $integer) { return $integer % 2 === 0;})    // [0, 2, 4, 6, 8, 8, 6, 4, 2, 0]
    ->map(function (int $integer) { return $integer + 1; })    // [1, 3, 5, 7, 9, 9, 7, 5, 3, 1]
    ->dedupe()    // [1, 3, 5, 7, 9, 9, 7, 5, 3, 1]
    ->distinct()    // [1, 3, 5, 7, 9]
    ->take(3)     // [1, 3, 5]
    ->sum()    // 9
;