
- PHP Tutorial
- PHP - Home
- PHP - Introduction
- PHP - Environment Setup
- PHP - Syntax Overview
- PHP - Variable Types
- PHP - Constants
- PHP - Operator Types
- PHP - Decision Making
- PHP - Loop Types
- PHP - Arrays
- PHP - Strings
- PHP - Web Concepts
- PHP - GET & POST
- PHP - File Inclusion
- PHP - Files & I/O
- PHP - Functions
- PHP - Cookies
- PHP - Sessions
- PHP - Sending Emails
- PHP - File Uploading
- PHP - Coding Standard
- Advanced PHP
- PHP - Predefined Variables
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Bugs Debugging
- PHP - Date & Time
- PHP & MySQL
- PHP & AJAX
- PHP & XML
- PHP - Object Oriented
- PHP - For C Developers
- PHP - For PERL Developers
- PHP Form Examples
- PHP - Form Introduction
- PHP - Validation Example
- PHP - Complete Form
- PHP login Examples
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP AJAX Examples
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML Example
- PHP - XML Introduction
- PHP - Simple XML
- PHP - Simple XML GET
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Frame Works
- PHP - Frame Works
- PHP - Core PHP vs Frame Works
- PHP Design Patterns
- PHP - Design Patterns
- PHP Function Reference
- PHP - Built-In Functions
- PHP Useful Resources
- PHP - Questions & Answers
- PHP - Useful Resources
- PHP - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Strengths
- 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.
Weaknesses
- Can’t be converted to an array when objects are used as keys.
Syntax
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 ) }
Predefined Constants
Ds\Map::MIN_CAPACITY
Sr.No | Function & Description |
---|---|
1 |
This Function can allocate enough memory for the required capacity. |
2 |
This Function can update update all values by applying a callback function to each value. |
3 |
This Function can return the current capacity. |
4 |
This Function can remove remove all values. |
5 |
This Function can return the shallow copy of a map. |
6 |
This Function can return the number of values in a map. |
7 |
This Function can create a new map by using keys that aren't in another map. |
8 |
This Function can create a new map by using a callable to determine which pairs to include. |
9 |
This Function can return the first pair in a map. |
10 |
This Function can return the value for a given key. |
11 |
This Function can determine whether the map contain a given key. |
12 |
This Function can determine whether the map contain a given value. |
13 |
This Function can create a new map by intersecting keys with another map. |
14 |
This Function can return return whether the map is empty. |
15 | Ds\Map::jsonSerialize() Function This Function can return a representation that can be converted to JSON. |
16 |
This Function can return the set of map's keys. |
17 |
This Function can sort the map in-place by key. |
18 |
This Function can return a copy, sorted by key. |
19 |
This Function can return the last pair of a map. |
20 |
This Function can return the result of applying a callback to each value. |
21 |
This Function can return the result of adding all given associations. |
22 |
This Function can return a sequence containing all pairs of the map. |
23 |
This Function can associate a key with a value. |
24 |
This Function can associate all key-value pairs of traversable object or array. |
25 |
This Function can reduce the map to a single value by using a callback function. |
26 |
This Function can remove and return a value by key. |
27 |
This Function can can reverse the map in-place. |
28 |
This Function can return a reversed copy. |
29 |
This Function can return the pair at a given positional index. |
30 |
This Function can return a subset of the map defined by starting index and length. |
31 |
This Function can sort the map in-place by value. |
32 |
This Function can return a copy sorted by value. |
33 |
This Function can return the sum of all values in a map. |
34 |
This Function can convert a map to an array. |
35 |
This Function can create a new map using values from the current instance and another map. |
36 |
This Function can return a sequence of the map's values. |
37 |
This Function can create a new map using the keys of either current instance or of another map, but not of both. |