Download the PHP package tonix-tuft/linked-hash-map without Composer
On this page you can find all versions of the php package tonix-tuft/linked-hash-map. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tonix-tuft/linked-hash-map
More information about tonix-tuft/linked-hash-map
Files in tonix-tuft/linked-hash-map
Package linked-hash-map
Short Description How I would implement a linked hash map in PHP if PHP wouldn't have associative arrays.
License MIT
Informations about the package linked-hash-map
linked-hash-map
How I would implement a linked hash map in PHP if PHP wouldn't have associative arrays.
Installation
Using Composer:
Usage
This map implements the ArrayAccess interface as well as the Iterator and Countable interfaces and therefore can be used as a built-in PHP array:
Using any PHP data type for the key
This map allows using any PHP type for the key (i.e. even an array or an object can be used for the key):
Differences and similarities between this map and built-in PHP arrays
The differences between this map and built-in PHP arrays as well as any similarities are the following:
-
Any PHP data type can be used for the key (
bool
,int
,float/double
,string
,array
,object
,callable
,iterable
,resource
) when using this map. This also means that for example a float/double1.5
will be used for the key as-is, whereas in built-in PHP arrays1.5
is type-juggled to1
: -
This map allows prepending instead of appending when setting the
LinkedHashMap::INSERT_MODE_PREPEND
flag (using thesetInsertMode
method): -
This map also allows setting the loop order (iteration) order (using the
setLoopOrder
method), whether normal (LinkedHashMap::LOOP_ORDER_NORMAL
, the default) or reversed (LinkedHashMap::LOOP_ORDER_REVERSE
): -
Appending/prepending to the map works in the same way as with built-in PHP arrays (a positional index (an
int or integer string >= 0
) is created or the highest positional index used so far is incremented internally). Accessing an unknown index does not trigger/emit a notice (just returnsNULL
): - Because ArrayAccess::offsetSet doesn't allow to differentiate between
NULL
and an append/prepend operation ($map[] = 'A value'
),NULL
cannot be used for the key. UsingNULL
for the key will be considered as an append/prepend operation. As built-in PHP arrays mapNULL
to an empty string''
, this shouldn't be an issue:
Using a custom hash code
Internally, the map computes the hash for the given key in order to retrieve the corresponding value using the package int-hash.
If the key is an instance of a class implementing the LinkedHashMap\HashCodeInterface
interface, its hashCode
method will be called and the returned hash code (an integer) will be used instead:
License
MIT © Anton Bagdatyev (Tonix)
All versions of linked-hash-map with dependencies
tonix-tuft/int-hash Version ^1.0
tonix-tuft/php-utils Version ^1.15
tonix-tuft/php-declarative-factory Version ^1.3
tonix-tuft/fun Version ^1.3