PHP - Map Functions

The Map is a sequential collection of key-value pairs, almost identical to an array used in a similar context. The keys can be of any type but must be unique, and the values are replaced if added to the map by using the same key.
Keys and values can be any type, including objects.
Supports array syntax (square brackets).
Insertion order is preserved.
Performance and memory efficiency is very similar to an array.
Automatically frees allocated memory when its size drops low enough.
Can’t be converted to an array when objects are used as keys.
Ds\Map implements Ds\Collection {
   /* Constants */   
   
   const int MIN_CAPACITY = 16 ;
   /* Methods */
   
   public void allocate( int $capacity )
   public void apply( callable $callback )
   public int capacity( void )
   public void clear( void )
   public Ds\Map copy( void )
   public Ds\Map diff( Ds\Map $map )
   public Ds\Map filter([ callable $callback ] )
   public Ds\Pair first( void )
   public mixed get( mixed $key [, mixed $default ] )
   public bool hasKey( mixed $key )
   public bool hasValue( mixed $value )
   public Ds\Map intersect( Ds\Map $map )
   public bool isEmpty( void )
   public Ds\Set keys( void )
   public void ksort([ callable $comparator ] )
   public Ds\Map ksorted([ callable $comparator ] )
   public Ds\Pair last( void )
   public Ds\Map map( callable $callback )
   public Ds\Map merge( mixed $values )
   public Ds\Sequence pairs( void )
   public void put( mixed $key , mixed $value )
   public void putAll( mixed $pairs )
   public mixed reduce( callable $callback [, mixed $initial ] )
   public mixed remove( mixed $key [, mixed $default ] )
   public void reverse( void )
   public Ds\Map reversed( void )
   public Ds\Pair skip( int $position )
   public Ds\Map slice int $index [, int $length ] )
   public void sort([ callable $comparator ] )
   public Ds\Map sorted([ callable $comparator ] )
   public number sum( void )
   public array toArray( void )
   public Ds\Map union( Ds\Map $map )
   public Ds\Sequence values( void )
   public Ds\Map xor( Ds\Map $map )
}
Ds\Map::MIN_CAPACITY
Ds\Map::allocate() Function
This Function can allocate enough memory for the required capacity.
Ds\Map::apply() Function
This Function can update update all values by applying a callback function to each value.
Ds\Map::capacity() Function
This Function can return the current capacity.
Ds\Map::clear() Function
This Function can remove remove all values.
Ds\Map::copy() Function
This Function can return the shallow copy of a map.
Ds\Map::count() Function
This Function can return the number of values in a map.
Ds\Map::diff() Function
This Function can create a new map by using keys that aren't in another map.
Ds\Map::filter() Function
This Function can create a new map by using a callable to determine which pairs to include.
Ds\Map::first() Function
This Function can return the first pair in a map.
Ds\Map::get() Function
This Function can return the value for a given key.
Ds\Map::hasKey() Function
This Function can determine whether the map contain a given key.
Ds\Map::hasValue() Function
This Function can determine whether the map contain a given value.
Ds\Map::intersect() Function
This Function can create a new map by intersecting keys with another map.
Ds\Map::isEmpty() Function
This Function can return return whether the map is empty.
Ds\Map::jsonSerialize() Function
This Function can return a representation that can be converted to JSON.
Ds\Map::keys() Function
This Function can return the set of map's keys.
Ds\Map::ksort() Function
This Function can sort the map in-place by key.
Ds\Map::ksorted() Function
This Function can return a copy, sorted by key.
Ds\Map::last() Function
This Function can return the last pair of a map.
Ds\Map::map() Function
This Function can return the result of applying a callback to each value.
Ds\Map::merge() Function
This Function can return the result of adding all given associations.
Ds\Map::pairs() Function
This Function can return a sequence containing all pairs of the map.
Ds\Map::put() Function
This Function can associate a key with a value.
Ds\Map::putAll() Function
This Function can associate all key-value pairs of traversable object or array.
Ds\Map::reduce() Function
This Function can reduce the map to a single value by using a callback function.
Ds\Map::remove() Function
This Function can remove and return a value by key.
Ds\Map::reverse() Function
This Function can can reverse the map in-place.
Ds\Map::reversed() Function
This Function can return a reversed copy.
Ds\Map::skip() Function
This Function can return the pair at a given positional index.
Ds\Map::slice() Function
This Function can return a subset of the map defined by starting index and length.
Ds\Map::sort() Function
This Function can sort the map in-place by value.
Ds\Map::sorted() Function
This Function can return a copy sorted by value.
Ds\Map::sum() Function
This Function can return the sum of all values in a map.
Ds\Map::toArray() Function
This Function can convert a map to an array.
Ds\Map::union() Function
This Function can create a new map using values from the current instance and another map.
Ds\Map::values() Function
This Function can return a sequence of the map's values.
Ds\Map::xor() Function
This Function can create a new map using the keys of either current instance or of another map, but not of both.

    45 Lectures 
     9 hours 

 Malhar Lathkar

    34 Lectures 
     4 hours 

 Syed Raza

    84 Lectures 
     5.5 hours 

 Frahaan Hussain

    17 Lectures 
     1 hours 

 Nivedita Jain

    100 Lectures 
     34 hours 

 Azaz Patel

    43 Lectures 
     5.5 hours 

 Vijay Kumar Parvatha Reddy
 Print
 Add Notes
 Bookmark this page