PHP code example of im0rtality / underscore

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

    

im0rtality / underscore example snippets


    Underscore::from([1,2,3,4,5])
            // convert array format
        ->map(function($num) { return ['number' => $num];})
            // filter out odd elements
        ->filter(function($item) { return ($item['number'] % 2) == 0;})
            // vardump elements
        ->invoke(function($item) { var_dump($item);})
            // changed my mind, I only want numbers
        ->pick('number')
            // add numbers to 1000
        ->reduce(function($sum, $num) { $sum += $num; return $sum; }, 1000)
            // take result
        ->value();
            // 1006