Version 3.5 of the PHP Map package includes more methods to work with collections of strings easily:
- ltrim(): Removes chars from the left
- rtrim(): Removes chars from the right
- strAfter(): Returns the strings after
- strBefore(): Returns the strings before
All these methods are multi-byte character aware and use UTF-8 encoding by default.
Examples:
“`php Map::from( [” abc\n”, “\tcde\r\n”] )->ltrim(); // [“abc\n”, “cde\r\n”]
Map::from( [“a b c”, “cbxa”] )->rtrim( ‘abc’ ); // [“a b “, “cbx”]
Map::from( [‘abc’] )->strAfter( ‘b’ ); // [‘c’]
Map::from( [‘äöüß’] )->strBefore( ‘ü’ ); // [‘äö’] “`
For more examples, look at https://php-map.org
Why PHP Map?
Instead of:
php $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:
php $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 🙂
submitted by /u/aimeos
[link] [comments]
More Stories
Will County, Illinois 1864 Map – May 20, 2023 at 04:14AM
This kid on Google Map trying to get by – April 27, 2023 at 05:05PM
World of Hyatt: Complete list of all-inclusive properties in Europe (with map) – April 27, 2023 at 04:57PM