Piper is a pipe operator-first PHP utility library for array and string manipulation. It ports Laravel's collection and string utility methods to standalone functions that work seamlessly with PHP 8.5's pipe operator.
It comes with array helpers:
use function Spatie\Piper\Arr\{filter, map};
$popular = $posts
|> filter(fn (Post $post) => $post->views > 1000)
|> map(fn (Post $post) => $post->title);
And string helpers:
use function Spatie\Piper\Str\{lower, replace};
'Hello, world!'
|> lower()
|> replace('world', 'Piper');
Since all functions work with primitives, you can mix and match:
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('.');
##We have badges!