fbpx
December 28, 2024

PHP Map 3.3 released – Collections made easy! – November 24, 2022 at 05:53AM

Version 3.3 of the PHP Map package includes more methods to work with collections of strings easily:

  • strContains(): Tests if the passed string is part of one of the entries
  • strStarts(): Tests if one of the entries starts with the passed string
  • strEnds(): Tests if one of the entries ends with the passed string
  • strLower(): Converts all alphabetic characters to lower case
  • strUpper(): Converts all alphabetic characters to upper case

All these methods are multi-byte character aware and use UTF-8 encoding by default.

Examples:

“` Map::from( [‘abc’] )->strContains( ‘b’ ); // true

Map::from( [‘abc’] )->strStarts( ‘ab’ ); // true

Map::from( [‘abc’] )->strEnds( ‘bc’ ); // true

Map::from( [‘ΤΆΧΙΣΤΗ’] )->strUpper(); // [“τάχιστη”]

Map::from( [‘τάχιστη’] )->strUpper(); // [“ΤΆΧΙΣΤΗ”] “`

https://php-map.org

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 🙂

https://php-map.org

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

%d bloggers like this: