PHP code example of formigone / php-chain

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

    

formigone / php-chain example snippets


    $users = array(
        array(
            'id' => 4,
            'username' => 'jshep',
            'firstName' => 'Jack',
            'lastName' => 'Shepherd',
            'active' => true
         ),
        array(
            'id' => 8,
            'username' => 'jlock',
            'firstName' => 'John',
            'lastName' => 'Lock',
            'active' => false
         ),
        // ...
        array(
            'id' => 23,
            'username' => 'jj-jacob',
            'firstName' => 'Jacob',
            'lastName' => null,
            'active' => false
        ),
        array(
            'id' => 42,
            'username' => 'smokey',
            'firstName' => 'Esau',
            'lastName' => 'Iratus',
            'active' => true
        ),
    );

    $activeUsers = array_filter($users, function($user) {
          return $user['active'];
    });

    $activeUsernames = array_map(function($user) {
          return $user['username'];
    }, $activeUsers);

    $activeUsernames = Formigone\Chain::from($users)
         ->filter(function($user){ return $user['active']; })
         ->map(function($user){ return $user['username']; })
         ->get();