We just released version 4.0 of PHP Map, the PHP array/collection package for working with arrays and collections easily.
The new version is a major release including PHP 8+ with strict typing and includes:
- Requires PHP 8+, dropped PHP 7 support
- All method signatures now use union types (\Closure|int|string, \Closure|\Throwable|bool, etc.) instead of mixed
- Return type declarations (: mixed) added to methods like at(), first(), find(), etc.
- Removed deprecated inString() — use strContains() instead
- strReplace() is now case-sensitive by default ($case parameter flipped to true)
- Implements() requires boolean type for second parameter
- Performance improvements
Upgrade from 3.x should be straightforward if you're already on PHP 8. The main things to watch for are the strReplace() default change and the removed inString() method. Have a look at the complete documentation at https://php-map.org and the upgrade guide for details.
Why PHP Map?
Instead of:
$list = [['id' => 'one', 'value' => 'v1']]; $list[] = ['id' => 'two', 'value' => 'v2'] unset( $list[0] ); $list = array_filter( $list ); sort( $list ); $pairs = array_column( $list, 'value', 'id' ); $value = reset( $pairs ) ?: null;Just write:
$value = map( [['id' => 'one', 'value' => 'v1']] ) ->push( ['id' => 'two', 'value' => 'v2'] ) ->remove( 0 ) ->filter() ->sort() ->col( 'value', 'id' ) ->first();There are several implementations of collections available in PHP but the PHP Map package is feature-rich, dependency free and loved by most developers according to GitHub.
Feel free to like, comment or give a star :-)
[link] [comments]








English (US) ·