MJExtension
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.
- 8.5k
- Objective-C
- MIT
- 3 y ago
PHP arrays and collections made easy
Repo aimeos/map, read from GitHub 14 h ago. aimeos has not joined Take My Repo.
aimeos/map is a public repo on GitHub by aimeos. PHP arrays and collections made easy. It declares the MIT license on GitHub. It is written mainly in PHP, has 4,324 stars and last changed on 2026-07-07. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Easy and elegant handling of PHP arrays by using an array-like collection object as offered by jQuery and Laravel Collections.
composer req aimeos/map
Supported PHP versions:
Table of contents
Instead of:
$list = [['id' => 'one', 'value' => 'value1'], ['id' => 'two', 'value' => 'value2'], null];
$list[] = ['id' => 'three', 'value' => 'value3']; // add element
unset( $list[0] ); // remove element
$list = array_filter( $list ); // remove empty values
sort( $list ); // sort elements
$pairs = array_column( $list, 'value', 'id' ); // create ['three' => 'value3']
$value = reset( $pairs ) ?: null; // return first value
Only use:
$list = [['id' => 'one', 'value' => 'value1'], ['id' => 'two', 'value' => 'value2'], null];
$value = map( $list ) // create Map
->push( ['id' => 'three', 'value' => 'value3'] ) // add element
->remove( 0 ) // remove element
->filter() // remove empty values
->sort() // sort elements
->col( 'value', 'id' ) // create ['three' => 'value3']
->first(); // return first value
You can still use:
$map[] = ['id' => 'three', 'value' => 'value3'];
$value = $map[0];
count( $map );
foreach( $map as $key => value );
Use callbacks:
Also, the map object allows you to pass anonymous functions to a lot of methods, e.g.:
$map->each( function( $val, $key ) {
echo $key . ': ' . $val;
} );
jQuery style:
If your map elements are objects, you can call their methods for each object and get the result as new map just like in jQuery:
// MyClass implements setStatus() (returning $this) and getCode() (initialized by constructor)
$map = Map::from( ['a' => new MyClass( 'x' ), 'b' => new MyClass( 'y' )] );
$map->setStatus( 1 )->getCode()->toArray();
This will call setStatus( 1 ) on both objects. If setStatus() implementation
returns $this, the new map will also contain:
['a' => MyClass(), 'b' => MyClass()]
On those new map elements, getCode() will be called which returns x for the
first object and y for the second. The map created from the results of getCode()
will return:
['a' => 'x', 'b' => 'y']
function is_map function map __construct __call __callStatic after all any arsort arsorted asort asorted at avg before bool call cast chunk clear clone col collapse combine concat contains copy count countBy dd delimiter diff diffAssoc diffKeys dump duplicates each empty equals every except explode fill filter find findKey first firstKey flat flatten flip float from fromJson get getIterator grep groupBy has if ifAny ifEmpty implements in includes index insertAfter insertAt insertBefore int intersect intersectAssoc intersectKeys is isEmpty isList isObject isNumeric isScalar isSole isString join jsonSerialize keys krsort krsorted ksort ksorted last lastKey ltrim map max merge method min none nth offsetExists offsetGet offsetSet offsetUnset only order pad partition percentage pipe pluck pop pos prefix prepend pull push put random reduce reject rekey remove replace restrict reverse reversed rsort rsorted rtrim search sep set shift shuffle shuffled skip slice sliding sole some sort sorted splice strAfter strBefore strCompare strContains strContainsAll strEnds strEndsAll string strLower strReplace strStarts strStartsAll strUpper suffix sum take tap times to toArray toJson toReversed toSorted toUrl transform transpose traverse tree trim uasort uasorted uksort uksorted unflatten union unique unshift usort usorted values walk where with zip
Tests if the variable is a map object
function is_map( mixed $var ) : bool
$var Variable to testExamples:
is_map( new Map() );
// true
is_map( [] );
// false
Returns a new map for the passed elements.
function map( mixed $items = [] ) : \Aimeos\Map
$items List of elements or single valueExamples:
// array
map( [] );
// null
map( null );
// scalar
map( 'a' );
// object
map( new \stdClass() );
// map object
map( new Map() );
// iterable object
map( new ArrayObject() );
// closure evaluated lazily
map( function() {
return [];
} );
See also:
Creates a new map object.
public function __construct( mixed $elements = [] )
$elements Single element, list of elements, Map object, iterable objects or iterators, everything elseExamples:
// array
new Map( [] );
// null
new Map( null );
// scalar
new Map( 'a' );
// object
new Map( new \stdClass() );
// map object
new Map( new Map() );
// iterable object
new Map( new ArrayObject() );
// closure evaluated lazily
new Map( function() {
return [];
} );
Handles dynamic calls to custom methods for the class.
public function __call( string $name, array $params ) : mixed
$name Method name$params List of parametersCalls a custom method added by Map::method(). The called method
has access to the internal array by using $this->list().
Examples:
Map::method( 'case', function( $case = CASE_LOWER ) {
return new static( array_change_key_case( $this->list(), $case ) );
} );
Map::from( ['a' => 'bar'] )->case( CASE_UPPER );
// ['A' => 'bar']
This does also allow calling object methods if the items are objects:
$item = new MyClass(); // with method setId() (returning $this) and getCode() implemented
Map::from( [$item, $item] )->setId( null )->getCode()->toArray();
This will call the setId() method of each element in the map and
use their return values to create a new map. On the new map, the getCode()
method is called for every element and its return values are also stored in a new
map. This last map is then returned and the map keys from the original map are
preserved in the returned map.
If the elements are not objects or the method isn't callable, they are skipped and if this applies to all elements, an empty map is returned.
See also:
Handles static calls to custom methods for the class.
public static function __callStatic( string $name, array $params ) : mixed
$name Method name$params List of parametersCalls a custom method added by Map::method() statically. The called method has no access to the internal array because no object is available.
Examples:
Map::method( 'foo', function( $arg1, $arg2 ) {} );
Map::foo( $arg1, $arg2 );
See also:
Returns the elements after the given one.
public function after( \Closure|int|string $value ) : self
$value Value or function with (item, key) parametersThe keys are preserved using this method.
Examples:
Map::from( [0 => 'b', 1 => 'a'] )->after( 'b' );
// [1 => 'a']
Map::from( ['a' => 1, 'b' => 0] )->after( 1 );
// ['b' => 0]
Map::from( [0 => 'b', 1 => 'a'] )->after( 'c' );
// []
Map::from( ['a', 'c', 'b'] )->after( function( $item, $key ) {
return $item >= 'c';
} );
// [2 => 'b']
See also:
Returns the elements as a plain array.
public function all() : array
Examples:
Map::from( ['a'] )->all();
// ['a']
This method is for compatibility to Laravel Collections. Use to() instead if possible.
See also:
Tests if at least one element satisfies the callback function.
public function any( callable $callback ) : bool
$callback Function with (item, key) parameterExamples:
Map::from( ['a', 'b'] )->any( function( $item, $key ) {
return $item === 'a';
} );
// TRUE
Map::from( ['a', 'b'] )->any( function( $item, $key ) {
return !is_string( $item );
} );
// FALSE
See also:
Sorts all elements in reverse order and maintains the key association.
public function arsort( int $options = SORT_REGULAR ) : self
$options Sort options for arsort()The keys are preserved using this method and no new map is created.
The $options parameter modifies how the values are compared. Possible parameter values are:
setlocale()natsort()Examples:
Map::from( ['b' => 0, 'a' => 1] )->arsort();
// ['a' => 1, 'b' => 0]
Map::from( ['a', 'b'] )->arsort();
// ['b', 'a']
Map::from( [0 => 'C', 1 => 'b'] )->arsort();
// [1 => 'b', 0 => 'C']
Map::from( [0 => 'C', 1 => 'b'] )->arsort( SORT_STRING|SORT_FLAG_CASE );
// [0 => 'C', 1 => 'b'] because 'C' -> 'c' and 'c' > 'b'
See also:
Sorts a copy of all elements in reverse order and maintains the key association.
public function arsorted( int $options = SORT_REGULAR ) : self
$options Sort options for arsort()The keys are preserved using this method and a new map is created.
The $options parameter modifies how the values are compared. Possible parameter values are:
setlocale()natsort()Examples:
Map::from( ['b' => 0, 'a' => 1] )->arsorted();
// ['a' => 1, 'b' => 0]
Map::from( ['a', 'b'] )->arsorted();
// ['b', 'a']
Map::from( [0 => 'C', 1 => 'b'] )->arsorted();
// [1 => 'b', 0 => 'C']
Map::from( [0 => 'C', 1 => 'b'] )->arsorted( SORT_STRING|SORT_FLAG_CASE );
// [0 => 'C', 1 => 'b'] because 'C' -> 'c' and 'c' > 'b'
See also:
Sorts all elements and maintains the key association.
public function asort( int $options = SORT_REGULAR ) : self
$options Sort options for asort()The keys are preserved using this method and no new map is created.
The parameter modifies how the values are compared. Possible parameter values are:
setlocale()natsort()Examples:
Map::from( ['a' => 1, 'b' => 0] )->asort();
// ['b' => 0, 'a' => 1]
Map::from( [0 => 'b', 1 => 'a'] )->asort();
// [1 => 'a', 0 => 'b']
Map::from( [0 => 'C', 1 => 'b'] )->asort();
// [0 => 'C', 1 => 'b'] because 'C' < 'b'
Map::from( [0 => 'C', 1 => 'b'] )->asort( SORT_STRING|SORT_FLAG_CASE );
// [1 => 'b', 0 => 'C'] because 'C' -> 'c' and 'c' > 'b'
See also:
Sorts a copy of all elements and maintains the key association.
public function asorted( int $options = SORT_REGULAR ) : self
$options Sort options for asort()The keys are preserved using this method and a new map is created.
The parameter modifies how the values are compared. Possible parameter values are:
setlocale()natsort()Examples:
Map::from( ['a' => 1, 'b' => 0] )->asorted();
// ['b' => 0, 'a' => 1]
Map::from( [0 => 'b', 1 => 'a'] )->asorted();
// [1 => 'a', 0 => 'b']
Map::from( [0 => 'C', 1 => 'b'] )->asorted();
// [0 => 'C', 1 => 'b'] because 'C' < 'b'
Map::from( [0 => 'C', 1 => 'b'] )->asorted( SORT_STRING|SORT_FLAG_CASE );
// [1 => 'b', 0 => 'C'] because 'C' -> 'c' and 'c' > 'b'
See also:
Returns the value at the given position.
public function at( int $pos ) : mixed
$pos Position of the value in the mapThe position starts from zero and a position of "0" returns the first element of the map, "1" the second and so on. If the position is negative, the sequence will start from the end of the map.
Examples:
Map::from( [1, 3, 5] )->at( 0 );
// 1
Map::from( [1, 3, 5] )->at( 1 );
// 3
Map::from( [1, 3, 5] )->at( -1 );
// 5
Map::from( [1, 3, 5] )->at( 3 );
// NULL
See also:
Returns the average of all integer and float values in the map.
public function avg( \Closure|string|null $col = null ) : float
$col Closure, key or path to the values in the nested array or object to compute the average forNon-numeric values will be removed before calculation.
This does also work for multi-dimensional arrays by passing the keys
of the arrays separated by the delimiter ("/" by default), e.g. "key1/key2/key3"
to get "val" from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
public properties of objects or objects implementing __isset() and __get() methods.
Examples:
Map::from( [1, 3, 5] )->avg();
// 3
Map::from( [1, null, 5] )->avg();
// 3
Map::from( [1, 'sum', 5] )->avg();
// 2
Map::from( [['p' => 30], ['p' => 50], ['p' => 10]] )->avg( 'p' );
// 30
Map::from( [['i' => ['p' => 30]], ['i' => ['p' => 50]]] )->avg( 'i/p' );
// 40
Map::from( [['i' => ['p' => 30]], ['i' => ['p' => 50]]] )->avg( fn( $val, $key ) => $val['i']['p'] ?? null );
// 40
Map::from( [['p' => 30], ['p' => 50], ['p' => 10]] )->avg( fn( $val, $key ) => $key < 1 ? $val : null );
// 30
See also:
Returns the elements before the given one.
public function before( \Closure|int|string $value ) : self
$value Value or function with (item, key) parametersThe keys are preserved using this method.
Examples:
Map::from( ['a' => 1, 'b' => 0] )->before( 0 );
// ['a' => 1]
Map::from( [0 => 'b', 1 => 'a'] )->before( 'a' );
// [0 => 'b']
Map::from( [0 => 'b', 1 => 'a'] )->before( 'c' );
// []
Map::from( ['a', 'c', 'b'] )->before( function( $item, $key ) {
return $key >= 1;
} );
// [0 => 'a']
See also:
Returns an element by key and casts it to boolean if possible.
public function bool( int|string $key, \Closure|\Throwable|bool $default = false ) : bool
$key Key or path to the requested item$default Default value if key isn't foundThis does also work to map values from multi-dimensional arrays by passing the keys
of the arrays separated by the delimiter ("/" by default), e.g. key1/key2/key3
to get val from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
public properties of objects or objects implementing __isset() and __get() methods.
Examples:
Map::from( ['a' => true] )->bool( 'a' );
// true
Map::from( ['a' => '1'] )->bool( 'a' );
// true (casted to boolean)
Map::from( ['a' => 1.1] )->bool( 'a' );
// true (casted to boolean)
Map::from( ['a' => '10'] )->bool( 'a' );
// true (casted to boolean)
Map::from( ['a' => 'abc'] )->bool( 'a' );
// true (casted to boolean)
Map::from( ['a' => ['b' => ['c' => true]]] )->bool( 'a/b/c' );
// true
Map::from( [] )->bool( 'c', function( $val ) { return rand( 1, 2 ); } );
// true (value returned by closure is casted to boolean)
Map::from( [] )->bool( 'a', true );
// true (default value used)
Map::from( [] )->bool( 'a' );
// false
Map::from( ['b' => ''] )->bool( 'b' );
// false (casted to boolean)
Map::from( ['b' => null] )->bool( 'b' );
// false (null is not scalar)
Map::from( ['b' => [true]] )->bool( 'b' );
// false (arrays are not scalar)
Map::from( ['b' => resource] )->bool( 'b' );
// false (resources are not scalar)
Map::from( ['b' => new \stdClass] )->bool( 'b' );
// false (objects are not scalar)
Map::from( [] )->bool( 'c', new \Exception( 'error' ) );
// throws exception
See also:
Calls the given method on all items and returns the result.
public function call( string $name, array $params = [] ) : self
$name Method name$params List of parametersThis method can call methods on the map entries that are also implemented
by the map object itself and are therefore not reachable when using the
magic __call() method. If some entries are not objects or the method isn't
callable, they will be skipped.
The keys from the original map are preserved in the returned in the new map.
Examples:
$item = new MyClass( ['myprop' => 'val'] ); // implements methods get() and toArray()
Map::from( [$item, $item] )->call( 'get', ['myprop'] );
// ['val', 'val']
Map::from( [$item, $item] )->call( 'toArray' );
// [['myprop' => 'val'], ['myprop' => 'val']]
See also:
Casts all entries to the passed type.
public function cast( string $type = 'string' ) : self
$type Type to cast the values to ("string", "bool", "int", "float", "array", "object")Casting arrays and objects to scalar values won't return anything useful!
Examples:
Map::from( [true, 1, 1.0, 'yes'] )->cast();
// ['1', '1', '1.0', 'yes']
Map::from( [true, 1, 1.0, 'yes'] )->cast( 'bool' );
// [true, true, true, true]
Map::from( [true, 1, 1.0, 'yes'] )->cast( 'int' );
// [1, 1, 1, 0]
Map::from( [true, 1, 1.0, 'yes'] )->cast( 'float' );
// [1.0, 1.0, 1.0, 0.0]
Map::from( [new stdClass, new stdClass] )->cast( 'array' );
// [[], []]
Map::from( [[], []] )->cast( 'object' );
// [new stdClass, new stdClass]
See also:
Chunks the map into arrays with the given number of elements.
public function chunk( int $size, bool $preserve = false ) : self
$size Maximum size of the sub-arrays$preserve Preserve keys in new mapThe last chunk may contain less elements than the given number.
The sub-arrays of the returned map are plain PHP arrays. If you need Map objects, then wrap them with Map::from() when you iterate over the map.
Examples:
Map::from( [0, 1, 2, 3, 4] )->chunk( 3 );
// [[0, 1, 2], [3, 4]]
Map::from( ['a' => 0, 'b' => 1, 'c' => 2] )->chunk( 2 );
// [['a' => 0, 'b' => 1], ['c' => 2]]
See also:
Removes all elements from the current map.
public function clear() : self
Examples:
Map::from( [0, 1] )->clear();
// internal : []
See also:
Clones the map and all objects within.
public function clone() : self
The objects within the Map are NOT the same as before but new cloned objects.
This is different to copy(), which doesn't clone the objects within.
The keys are preserved using this method.
Examples:
Map::from( [new \stdClass, new \stdClass] )->clone();
// [new \stdClass, new \stdClass]
See also:
Returns the values of a single column/property from an array of arrays or objects in a new map.
public function col( ?string $valuecol = null, ?string $indexcol = null ) : self
$valuecol Name or path of the value property$indexcol Name or path of the index propertyIf $indexcol is omitted, it's value is NULL or not set, the result will be indexed from 0-n. Items with the same value for $indexcol will overwrite previous items and only the last one will be part of the resulting map.
This does also work to map values from multi-dimensional arrays by passing the keys
of the arrays separated by the delimiter ("/" by default), e.g. key1/key2/key3
to get val from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
public properties of objects or objects implementing __isset() and __get() methods.
Examples:
Map::from( [['id' => 'i1', 'val' => 'v1'], ['id' => 'i2', 'val' => 'v2']] )->col( 'val' );
// ['v1', 'v2']
Map::from( [['id' => 'i1', 'val' => 'v1'], ['id' => 'i2', 'val' => 'v2']] )->col( 'val', 'id' );
// ['i1' => 'v1', 'i2' => 'v2']
Map::from( [['id' => 'i1', 'val' => 'v1'], ['id' => 'i2', 'val' => 'v2']] )->col( null, 'id' );
// ['i1' => ['id' => 'i1', 'val' => 'v1'], 'i2' => ['id' => 'i2', 'val' => 'v2']]
Map::from( [['id' => 'ix', 'val' => 'v1'], ['id' => 'ix', 'val' => 'v2']] )->col( null, 'id' );
// ['ix' => ['id' => 'ix', 'val' => 'v2']]
Map::from( [['foo' => ['bar' => 'one', 'baz' => 'two']]] )->col( 'foo/baz', 'foo/bar' );
// ['one' => 'two']
Map::from( [['foo' => ['bar' => 'one']]] )->col( 'foo/baz', 'foo/bar' );
// ['one' => null]
Map::from( [['foo' => ['baz' => 'two']]] )->col( 'foo/baz', 'foo/bar' );
// ['two']
See also:
Collapses all sub-array elements recursively to a new map.
public function collapse( ?int $depth = null ) : self
$depth Number of levels to collapse for multi-dimensional arrays or NULL for allThe keys are preserved and already existing elements will be overwritten. This is also true for numeric keys! This method is similar than flat() but replaces already existing elements.
A value smaller than 1 for depth will return the same map elements. Collapsing does also work if elements implement the "Traversable" interface (which the Map object does).
Examples:
Map::from( [0 => ['a' => 0, 'b' => 1], 1 => ['c' => 2, 'd' => 3]] )->collapse();
// ['a' => 0, 'b' => 1, 'c' => 2, 'd' => 3]
Map::from( [0 => ['a' => 0, 'b' => 1], 1 => ['a' => 2]] )->collapse();
// ['a' => 2, 'b' => 1]
Map::from( [0 => [0 => 0, 1 => 1], 1 => [0 => ['a' => 2, 0 => 3], 1 => 4]] )->collapse();
// [0 => 3, 1 => 4, 'a' => 2]
Map::from( [0 => [0 => 0, 'a' => 1], 1 => [0 => ['b' => 2, 0 => 3], 1 => 4]] )->collapse( 1 );
// [0 => ['b' => 2, 0 => 3], 1 => 4, 'a' => 1]
Map::from( [0 => [0 => 0, 'a' => 1], 1 => Map::from( [0 => ['b' => 2, 0 => 3], 1 => 4] )] )->collapse();
// [0 => 3, 'a' => 1, 'b' => 2, 1 => 4]
See also:
Combines the values of the map as keys with the passed elements as values.
public function combine( iterable $values ) : self
$values Values of the new mapExamples:
Map::from( ['name', 'age'] )->combine( ['Tom', 29] );
// ['name' => 'Tom', 'age' => 29]
See also:
Pushs all of the given elements onto the map with new keys without creating a new map.
public function concat( iterable $elements ) : self
$elements List of elementsThe keys of the passed elements are NOT preserved!
Examples:
Map::from( ['foo'] )->concat( ['bar'] );
// ['foo', 'bar']
Map::from( ['foo'] )->concat( new Map( ['bar' => 'baz'] ) );
// ['foo', 'baz']
See also:
Determines if an item exists in the map.
public function contains( \Closure|iterable|string|int $key, ?string $operator = null, mixed $value = null ) : bool
This method combines the power of the where() method with some() to check
if the map contains at least one of the passed values or conditions.
$key Anonymous function with (item, key) parameter, element or list of elements to test against$operator Operator used for comparison$value Value used for comparisonCheck the where()] method for available operators.
Examples:
Map::from( ['a', 'b'] )->contains( 'a' );
// true
Map::from( ['a', 'b'] )->contains( ['a', 'c'] );
// true
Map::from( ['a', 'b'] )->contains( function( $item, $key ) {
return $item === 'a'
} );
// true
Map::from( [['type' => 'name']] )->contains( 'type', 'name' );
// true
Map::from( [['type' => 'name']] )->contains( 'type', '==', 'name' );
// true
See also:
Creates a new map with the same elements.
public function copy() : self
Both maps share the same array until one of the map objects modifies the array. Then, the array is copied and the copy is modfied (copy on write).
Examples:
$m = Map::from( ['foo', 'bar'] );
$m2 = $m->copy();
// internal: ['foo', 'bar'] both two maps
See also:
Counts the total number of elements in the map.
public function count() : int
Examples:
Map::from( ['foo', 'bar'] )->count();
// 2
See also:
Counts how often the same values are in the map.
public function countBy( \Closure|string|null $col = null ) : self
$col Key as "key1/key2/key3" or closure with (value) parameter returning the values for countingThis does also work for multi-dimensional arrays by passing the keys of the arrays separated by the delimiter ("/" by default), e.g. "key1/key2/key3" to get "val" from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to public properties of objects or objects implementing __isset() and __get() methods.
Examples:
Map::from( [1, 'foo', 2, 'foo', 1] )->countBy();
// [1 => 2, 'foo' => 2, 2 => 1]
Map::from( [1.11, 3.33, 3.33, 9.99] )->countBy();
// ['1.11' => 1, '3.33' => 2, '9.99' => 1]
Map::from( [['i' => ['p' => 1.11]], ['i' => ['p' => 3.33]], ['i' => ['p' => 3.33]]] )->countBy( 'i/p' );
// ['1.11' => 1, '3.33' => 2]
Map::from( ['a@gmail.com', 'b@yahoo.com', 'c@gmail.com'] )->countBy( function( $email ) {
return substr( strrchr( $email, '@' ), 1 );
} );
// ['gmail.com' => 2, 'yahoo.com' => 1]
See also:
Dumps the map content and terminates the script.
public function dd( ?callable $callback = null ) : void
$callback Function receiving the map elements as parameter (optional)The dd() method is very helpful to see what are the map elements passed
between two map methods in a method call chain. It stops execution of the
script afterwards to avoid further output.
Examples:
Map::from( ['a' => 'foo', 'b' => 'bar'] )->sort()->dd()->first();
/*
Array
(
[0] => bar
[1] => foo
)
*/
The first() method isn't executed at all.
Sets or returns the separator for paths to values in multi-dimensional arrays or objects.
public static function delimiter( ?string $char = null ) : string
$char Separator character, e.g. "." for "key.to.value" instaed of "key/to/value"The static method only changes the separator for new maps created afterwards. Already existing maps will continue to use the previous separator. To change the separator of an existing map, use the sep() method instead.
Examples:
Map::delimiter( '.' );
// '/'
Map::from( ['foo' => ['bar' => 'baz']] )->get( 'foo.bar' );
// 'baz'
See also:
Returns the keys/values in the map whose values are not present in the passed elements in a new map.
public function diff( iterable $elements, ?callable $callback = null ) : self
$elements List of elements$callback Function with (valueA, valueB) parameters and returns -1 (<), 0 (=) and 1 (>)Examples:
Map::from( ['a' => 'foo', 'b' => 'bar'] )->diff( ['bar'] );
// ['a' => 'foo']
If a callback is passed, the given function will be used to compare the values. The function must accept two parameters (value A and B) and must return -1 if value A is smaller than value B, 0 if both are equal and 1 if value A is greater than value B. Both, a method name and an anonymous function can be passed:
Map::from( [0 => 'a'] )->diff( [0 => 'A'], 'strcasecmp' );
// []
Map::from( ['b' => 'a'] )->diff( ['B' => 'A'], 'strcasecmp' );
// []
Map::from( ['b' => 'a'] )->diff( ['c' => 'A'], function( $valA, $valB ) {
return strtolower( $valA ) <=> strtolower( $valB );
} );
// []
All examples will return an empty map because both contain the same values when compared case insensitive.
The keys are preserved using this method.
See also:
Returns the keys/values in the map whose keys AND values are not present in the passed elements in a new map.
public function diffAssoc( iterable $elements, ?callable $callback = null ) : self
$elements List of elements$callback Function with (valueA, valueB) parameters and returns -1 (<), 0 (=) and 1 (>)Examples:
Map::from( ['a' => 'foo', 'b' => 'bar'] )->diffAssoc( new Map( ['foo', 'b' => 'bar'] ) );
// ['a' => 'foo']
If a callback is passed, the given function will be used to compare the values. The function must accept two parameters (valA, valB) and must return -1 if value A is smaller than value B, 0 if both are equal and 1 if value A is greater than value B. Both, a method name and an anonymous function can be passed:
Map::from( [0 => 'a'] )->diffAssoc( [0 => 'A'], 'strcasecmp' );
// []
Map::from( ['b' => 'a'] )->diffAssoc( ['B' => 'A'], 'strcasecmp' );
// []
Map::from( ['b' => 'a'] )->diffAssoc( ['c' => 'A'], function( $valA, $valB ) {
return strtolower( $valA ) <=> strtolower( $valB );
} );
// ['b' => 'a']
The first and second example will return an empty map because both contain the same values when compared case insensitive. In the third example, the keys doesn't match ("b" vs. "c").
The keys are preserved using this method.
See also:
Returns the key/value pairs from the map whose keys are not present in the passed elements in a new map.
public function diffKeys( iterable $elements, ?callable $callback = null ) : self
$elements List of elements$callback Function with (keyA, keyB) parameters and returns -1 (<), 0 (=) and 1 (>)Examples:
Map::from( ['a' => 'foo', 'b' => 'bar'] )->diffKeys( new Map( ['foo', 'b' => 'baz'] ) );
// ['a' => 'foo']
If a callback is passed, the given function will be used to compare the keys. The function must accept two parameters (key A and B) and must return -1 if key A is smaller than key B, 0 if both are equal and 1 if key A is greater than key B. Both, a method name and an anonymous function can be passed:
Map::from( [0 => 'a'] )->diffKeys( [0 => 'A'], 'strcasecmp' );
// []
Map::from( ['b' => 'a'] )->diffKeys( ['B' => 'X'], 'strcasecmp' );
// []
Map::from( ['b' => 'a'] )->diffKeys( ['c' => 'a'], function( $keyA, $keyB ) {
return strtolower( $keyA ) <=> strtolower( $keyB );
} );
// ['b' => 'a']
The first and second example will return an empty map because both contain the same keys when compared case insensitive. The third example will return ['b' => 'a'] because the keys doesn't match ("b" vs. "c").
The keys are preserved using this method.
See also:
Dumps the map content using the given function (print_r by default).
public function dump( ?callable $callback = null ) : self
$callback Function receiving the map elements as parameter (optional)The dump() method is very helpful to see what are the map elements passed
between two map methods in a method call chain.
Examples:
Map::from( ['a' => 'foo', 'b' => 'bar'] )->dump()->asort()->dump( 'var_dump' );
/*
Array
(
[a] => foo
[b] => bar
)
array(1) {
["b"]=>
string(3) "bar"
["a"]=>
string(3) "foo"
}
*/
Returns the duplicate values from the map.
public function duplicates( \Closure|string|null $col = null ) : self
$col Key, path of the nested array or anonymous function with ($item, $key) parameters returning the value for comparisonFor nested arrays, you have to pass the name of the column of the nested array which should be used to check for duplicates.
This does also work to map values from multi-dimensional arrays by passing the keys
of the arrays separated by the delimiter ("/" by default), e.g. key1/key2/key3
to get val from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
public properties of objects or objects implementing __isset() and __get() methods.
The keys in the result map are preserved.
Examples:
Map::from( [1, 2, '1', 3] )->duplicates()
// [2 => '1']
Map::from( [['p' => '1'], ['p' => 1], ['p' => 2]] )->duplicates( 'p' )
// [1 => ['p' => 1]]
Map::from( [['i' => ['p' => '1']], ['i' => ['p' => 1]]] )->duplicates( 'i/p' )
// [1 => ['i' => ['p' => 1]]]
Map::from( [['i' => ['p' => '1']], ['i' => ['p' => 1]]] )->duplicates( fn( $item, $key ) => $item['i']['p'] );
// [1 => ['i' => ['p' => 1]]]
See also:
Executes a callback over each entry until FALSE is returned.
public function each( callable $callback ) : self
$callback Function with (value, key) parameters and returns TRUE/FALSEExamples:
$result = [];
Map::from( [0 => 'a', 1 => 'b'] )->each( function( $value, $key ) use ( &$result ) {
$result[$key] = strtoupper( $value );
return false;
} );
// $result = [0 => 'A']
The $result array will contain [0 => 'A'] because FALSE is returned
after the first entry and all other entries are then skipped.
Determines if the map is empty or not.
public function empty() : bool
The method is equivalent to isEmpty().
Examples:
Map::from( [] )->empty();
// true
Map::from( ['a'] )->empty();
// false
See also:
Tests if the passed elements are equal to the elements in the map.
public function equals( iterable $elements ) : bool
$elements List of elements to test againstThe method differs to is() in the fact that it doesn't care about the keys by default. The elements are only loosely compared and the keys are ignored.
Values are compared by their string values:
(string) $item1 === (string) $item2
Examples:
Map::from( ['a'] )->equals( ['a', 'b'] );
// false
Map::from( ['a', 'b'] )->equals( ['b'] );
// false
Map::from( ['a', 'b'] )->equals( ['b', 'a'] );
// true
See also:
Verifies that all elements pass the test of the given callback.
public function every( callable $callback ) : bool
$callback Function with (value, key) parameters and returns TRUE/FALSEExamples:
Map::from( [0 => 'a', 1 => 'b'] )->every( function( $value, $key ) {
return is_string( $value );
} );
// true
Map::from( [0 => 'a', 1 => 100] )->every( function( $value, $key ) {
return is_string( $value );
} );
// false
See also:
Returns a new map without the passed element keys.
public function except( iterable|string|int $keys ) : self
$keys List of keys to removeThe keys in the result map are preserved.
Examples:
Map::from( ['a' => 1, 'b' => 2, 'c' => 3] )->except( 'b' );
// ['a' => 1, 'c' => 3]
Map::from( [1 => 'a', 2 => 'b', 3 => 'c'] )->except( [1, 3] );
// [2 => 'b']
See also:
Creates a new map with the string splitted by the delimiter.
public static function explode( string $delimiter, string $string, int $limit = PHP_INT_MAX ) : self
$delimiter Delimiter character, string or empty string$string String to split$limit Maximum number of element with the last element containing the rest of the stringA limit of "0" is treated the same as "1". If limit is negative, the rest of the string is dropped and not part of the returned map.
The string is split immediately and the returned map contains the parts.
Examples:
Map::explode( ',', 'a,b,c' );
// ['a', 'b', 'c']
Map::explode( '<-->', 'a a<-->b b<-->c c' );
// ['a a', 'b b', 'c c']
Map::explode( '', 'string' );
// ['s', 't', 'r', 'i', 'n', 'g']
Map::explode( '|', 'a|b|c', 2 );
// ['a', 'b|c']
Map::explode( '', 'string', 2 );
// ['s', 't', 'ring']
Map::explode( '|', 'a|b|c|d', -2 );
// ['a', 'b']
Map::explode( '', 'string', -3 );
// ['s', 't', 'r']
Creates a new map filled with given value.
public static function fill( int $num, mixed $value, int $start = 0 ) : self
$num Number of elements to create$value Value to fill the map with$start Start index for the elementsExamples:
Map::fill( 3, 'a' );
// [0 => 'a', 1 => 'a', 2 => 'a']
Map::fill( 3, 'a', 2 );
// [2 => 'a', 3 => 'a', 4 => 'a']
Map::fill( 3, 'a', -2 );
// [-2 => 'a', -1 => 'a', 0 => 'a'] (PHP 8)
// [-2 => 'a', 0 => 'a', 1 => 'a'] (PHP 7)
Applies a filter to all elements of the map and returns a new map.
public function filter( ?callable $callback = null ) : self
$callback Function with (item, key) parameters and returns TRUE/FALSEIf no callback is passed, all values which are empty, null or false will be removed if their value converted to boolean is FALSE:
(bool) $value === false
The keys in the result map are preserved.
Examples:
Map::from( [null, 0, 1, '', '0', 'a'] )->filter();
// [1, 'a']
Map::from( [2 => 'a', 6 => 'b', 13 => 'm', 30 => 'z'] )->filter( function( $value, $key ) {
return $key < 10 && $value < 'n';
} );
// ['a', 'b']
See also:
Returns the first/last matching element where the callback returns TRUE.
public function find( callable $callback, mixed $default = null, bool $reverse = false ) : mixed
$callback Function with (value, key) parameters and returns TRUE/FALSE$default Default value, closure or exception if the callback only returns FALSE$reverse TRUE to test elements from back to front, FALSE for front to back (default)Examples:
Map::from( ['a', 'c', 'e'] )->find( function( $value, $key ) {
return $value >= 'b';
} );
// 'c'
Map::from( ['a', 'c', 'e'] )->find( function( $value, $key ) {
return $value >= 'b';
}, null, true );
// 'e' because $reverse = true
Map::from( [] )->find( function( $value, $key ) {
return $value >= 'b';
}, 'none' );
// 'none'
Map::from( [] )->find( function( $value, $key ) {
return $value >= 'b';
}, fn() => 'none' );
// 'none'
Map::from( [] )->find( function( $value, $key ) {
return $value >= 'b';
}, new \Exception( 'error' ) );
// throws \Exception
See also:
Returns the first matching key where the callback returns TRUE.
public function findKey( callable $callback, mixed $default = null, bool $reverse = false ) : mixed
$callback Function with (value, key) parameters and returns TRUE/FALSE$default Default value, closure or exception if the callback only returns FALSE$reverse TRUE to test elements from back to front, FALSE for front to back (default)Examples:
Map::from( ['a', 'c', 'e'] )->findKey( function( $value, $key ) {
return $value >= 'b';
} );
// 1 because array has keys 0, 1 and 2
Map::from( ['a', 'c', 'e'] )->findKey( function( $value, $key ) {
return $value >= 'b';
}, null, true );
// 2 because array is reversed and 'e' >= 'b'
Map::from( [] )->findKey( function( $value, $key ) {
return $value >= 'b';
}, fn() => 'none' );
// default value 'none'
Map::from( [] )->findKey( function( $value, $key ) {
return $value >= 'b';
}, new \Exception( 'error' ) );
// throws exception
See also:
Returns the first element from the map.
public function first( mixed $default = null ) : mixed
$default Default value, closure or exception if the map contains no elementsUsing this method doesn't affect the internal array pointer.
Examples:
Map::from( ['a', 'b'] )->first();
// 'a'
Map::from( [] )->first( 'x' );
// 'x'
Map::from( [] )->first( new \Exception( 'error' ) );
// throws \Exception
Map::from( [] )->first( function() { return rand(); } );
// random integer
See also:
Returns the key of the first element from the map.
public function firstKey( mixed $default = null ) : mixed
$default Default value, closure or exception if the map contains no elementsUsing this method doesn't affect the internal array pointer.
Examples:
Map::from( ['a' => 1, 'b' => 2] )->firstKey();
// 'a'
Map::from( [] )->firstKey( 'x' );
// 'x'
Map::from( [] )->firstKey( new \Exception( 'error' ) );
// throws \Exception
Map::from( [] )->firstKey( function() { return rand(); } );
// random integer
See also:
Creates a new map with all sub-array elements added recursively.
public function flat( ?int $depth = null ) : self
$depth Number of levels to flatten multi-dimensional arraysThe keys are not preserved and the new map elements will be numbered from 0-n. A value smaller than 1 for depth will return the same map elements indexed from 0-n. Flattening does also work if elements implement the "Traversable" interface (which the Map object does).
This method is similar than collapse() but doesn't replace existing elements. Keys are NOT preserved using this method!
Examples:
Map::from( [[0, 1], [2, 3]] )->flat();
// [0, 1, 2, 3]
Map::from( [[0, 1], [[2, 3], 4]] )->flat();
// [0, 1, 2, 3, 4]
Map::from( [[0, 1], [[2, 3], 4]] )->flat( 1 );
// [0, 1, [2, 3], 4]
Map::from( [[0, 1], Map::from( [[2, 3], 4] )] )->flat();
// [0, 1, 2, 3, 4]
See also:
Creates a new map with keys joined recursively.
public function flatten( ?int $depth = null ) : self
$depth Number of levels to flatten multi-dimensional arrays or NULL for allTo create the original multi-dimensional array again, use the unflatten() method.
Examples:
Map::from( ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]] )->flatten();
// ['a/b/c' => 1, 'a/b/d' => 2, 'b/e' => 3]
Map::from( ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]] )->flatten( 1 );
// ['a/b' => ['c' => 1, 'd' => 2], 'b/e' => 3]
Map::from( ['a' => ['b' => ['c' => 1, 'd' => 2]], 'b' => ['e' => 3]] )->sep( '.' )->flatten();
// ['a.b.c' => 1, 'a.b.d' => 2, 'b.e' => 3]
See also:
Exchanges the keys with their values and vice versa.
public function flip() : self
Examples:
Map::from( ['a' => 'X', 'b' => 'Y'] )->flip();
// ['X' => 'a', 'Y' => 'b']
Returns an element by key and casts it to float if possible.
public function float( int|string $key, \Closure|\Throwable|float $default = 0.0 ) : float
$key Key or path to the requested item$default Default value if key isn't foundThis does also work to map values from multi-dimensional arrays by passing the keys
of the arrays separated by the delimiter ("/" by default), e.g. key1/key2/key3
to get val from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
public properties of objects or objects implementing __isset() and __get() methods.
Examples:
Map::from( ['a' => true] )->float( 'a' );
// 1.0 (casted to float)
Map::from( ['a' => 1] )->float( 'a' );
// 1.0 (casted to float)
Map::from( ['a' => '1.1'] )->float( 'a' );
// 1.1 (casted to float)
Map::from( ['a' => '10'] )->float( 'a' );
// 10.0 (casted to float)
Map::from( ['a' => ['b' => ['c' => 1.1]]] )->float( 'a/b/c' );
// 1.1
Map::from( [] )->float( 'c', function( $val ) { return 1.1; } );
// 1.1
Map::from( [] )->float( 'a', 1.1 );
// 1.0 (default value used)
Map::from( [] )->float( 'a' );
// 0.0
Map::from( ['b' => ''] )->float( 'b' );
// 0.0 (casted to float)
Map::from( ['b' => 'abc'] )->float( 'b' );
// 0.0 (casted to float)
Map::from( ['b' => null] )->float( 'b' );
// 0.0 (null is not scalar)
Map::from( ['b' => [true]] )->float( 'b' );
// 0.0 (arrays are not scalar)
Map::from( ['b' => #resource] )->float( 'b' );
// 0.0 (resources are not scalar)
Map::from( ['b' => new \stdClass] )->float( 'b' );
// 0.0 (objects are not scalar)
Map::from( [] )->float( 'c', new \Exception( 'error' ) );
// throws exception
See also:
Creates a new map instance if the value isn't one already.
public static function from( mixed $elements = [] ) : self
$elements List of elements or single valueExamples:
// array
Map::from( [] );
// null
Map::from( null );
// scalar
Map::from( 'a' );
// object
Map::from( new \stdClass() );
// map object
Map::from( new Map() );
// iterable object
Map::from( new ArrayObject() );
// closure evaluated lazily
Map::from( function() {
return [];
} );
See also:
Creates a new map instance from a JSON string.
public static function fromJson( string $json, int $options = JSON_BIGINT_AS_STRING ) : self
$json JSON encoded string$options Combination of JSON_* constantsThere are several options available for decoding the JSON string which are described in the PHP json_decode() manual. The parameter can be a single JSON_* constant or a bitmask of several constants combine by bitwise OR (|), e.g.:
The JSON string is decoded immediately and invalid JSON strings throw an exception while the map is created.
JSON_BIGINT_AS_STRING|JSON_INVALID_UTF8_IGNORE
Examples:
Map::fromJson( '["a", "b"]' );
// ['a', 'b']
Map::fromJson( '{"a": "b"}' );
// ['a' => 'b']
Map::fromJson( '""' );
['']
See also:
Returns an element from the map by key.
public function get( int|string $key, mixed $default = null ) : mixed
$key Key or path to the requested item$default Default value if no element matchesThis does also work to map values from multi-dimensional arrays by passing the keys
of the arrays separated by the delimiter ("/" by default), e.g. key1/key2/key3
to get val from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
public properties of objects or objects implementing __isset() and __get() methods.
Examples:
Map::from( ['a' => 'X', 'b' => 'Y'] )->get( 'a' );
// 'X'
Map::from( ['a' => 'X', 'b' => 'Y'] )->get( 'c', 'Z' );
// 'Z'
Map::from( ['a' => ['b' => ['c' => 'Y']]] )->get( 'a/b/c' );
// 'Y'
Map::from( [] )->get( 'c', new \Exception( 'error' ) );
// throws \Exception
Map::from( [] )->get( 'c', function() { return rand(); } );
// random integer
See also:
aimeos/map is a public repo on GitHub by aimeos. PHP arrays and collections made easy.
It declares the MIT license on GitHub.
Its maker tagged it for Windows. That is declared by the maker; Take My Repo has not tested it.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-07-07. GitHub counts 1 open issue and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.
A collection of (mostly) technical things every software developer should know about
Redisson: Valkey & Redis Java Client and Real-Time Data Platform. Sync/Async/RxJava/Reactive API. Extends Valkey and Redis with over 60 objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Spring, Tomcat, Scheduler, JCache API, Hibernate, RPC, local cache..
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.

Provide all my solutions and explanations in Chinese for all the Leetcode coding problems.
A collection of ZSH frameworks, plugins, themes and tutorials.
Laravel ecommerce package for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
Integrated online shop based on Laravel and the Aimeos e-commerce framework for ultra-fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce

Aimeos PHP e-commerce framework for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
Aimeos cloud-native, API-first ecommerce headless distribution based on Laravel for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/aimeos/mapTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.