PHP code example of spatie / piper

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

    

spatie / piper example snippets


use function Spatie\Piper\Arr\{filter, map};

$popular = $posts
    |> filter(fn (Post $post) => $post->views > 1000)
    |> map(fn (Post $post) => $post->title);

// ["Claude Talk Small. Code Still Big.", …]

use function Spatie\Piper\Str\{lower, replace};

'Hello, world!'
    |> lower()
    |> replace('world', 'Piper');

// "hello, Piper!"

use function Spatie\Piper\Arr\{filter, join, map, values};
use function Spatie\Piper\Str\{prefix, suffix};

[1, 2, 3, 4, 5, 6]
    |> filter(fn (int $i) => $i % 2 === 0)
    |> map(fn (int $i) => pow($i, 2))
    |> values()
    |> join(', ', ', and ')
    |> prefix('The winning numbers are ')
    |> suffix('.');

// "The winning numbers are 4, 16, and 36."