PHP code example of beauty-framework / collection

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

    

beauty-framework / collection example snippets


$collection = new Collection([
  ['name' => 'Kirill'],
  ['name' => 'Hui'],
  ['name' => 'Zver'],
]);

$filtered = $collection
    ->where('name', 'Kirill')
    ->map(fn($x) => strtoupper($x['name']))
    ->toArray();

$collection = new LazyCollection(fn() => yield from range(1, 1_000_000));

$result = $collection
    ->filter(fn($x) => $x % 2 === 0)
    ->take(5)
    ->flatMap(fn($x) => [$x, $x * 10])
    ->toArray();