PHP code example of blue3957 / creek

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

    

blue3957 / creek example snippets


$users = [
    ['name' => 'Arthur', 'active' => true],
    ['name' => 'Bernard', 'active' => false],
    ['name' => 'Claude', 'active' => true],
];

$activeNames = Creek::from($users)
    ->filter(fn($user) => $user['active'])
    ->map(fn($user) => $user['name'])
    ->toArray(); //["Arthur, Claude"]

//manipulation
public function map(Callable $callback): static;
public function filter(?Callable $callback = null): static;
public function usort(Callable $callback): static;
public function uksort(Callable $callback): static;
public function flatten(int $depth = 1): static;

//output
public function toArray(): array;
public function reduce(Callable $callback, mixed $initial = null): mixed;
public function join(?string $separator = null): string;