fbpx
May 10, 2024

PHP Map 3.5 released – Collections made easy! – March 22, 2023 at 07:09AM

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 🙂

https://php-map.org

submitted by /u/aimeos
[link] [comments]

%d bloggers like this: