PHP code example of phpsoftbox / collection

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

    

phpsoftbox / collection example snippets


use PhpSoftBox\Collection\Collection;

$users = Collection::from([
    ['id' => 1, 'name' => 'Alice', 'active' => true],
    ['id' => 2, 'name' => 'Bob',   'active' => false],
]);

$names = $users
    ->filter(fn (array $u) => $u['active'])
    ->map(fn (array $u) => $u['name'])
    ->values()
    ->all();

// ['Alice']

$config = Collection::from([])
    ->setPath('db.host', 'localhost')
    ->setPath('db.port', 3306)
    ->all();

// ['db' => ['host' => 'localhost', 'port' => 3306]]