Download the PHP package andydune/array-container without Composer
On this page you can find all versions of the php package andydune/array-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andydune/array-container
More information about andydune/array-container
Files in andydune/array-container
Package array-container
Short Description It profitable for better accessibility to values. It supports any filters and mutators.
License MIT
Homepage https://github.com/AndyDune/ArrayContainer
Informations about the package array-container
ArrayContainer
It offers convenient interface for encapsulated array. Implements strategy template for any number of filters.
Requirements
- PHP version >= 7.1
- Sting "It's probably me" inside your headphones.
Installation
Installation using composer:
Or if composer was not installed globally:
Or edit your composer.json
:
And execute command:
Simple access to array
You do not need to worry about existence any key.
Filters
Filters are callable objects. Filters are used during request properties with getters.
Modifiers
Modifier is an object of class witch implements AndyDune\ArrayContainer\Action\AbstractAction interface. It can be simple extented without modification main class.
Add keys to array if not exist.
There is source array:
You need to use it inside model. Model waits array with keys: type, key and value
Result array is:
Array shift maintaining key to data correlations.
It is source array with numeric keys.
After execution function array_shift
keys will be lost.
Array container action helps to avoid it.
Result array is:
Add value to nested array
We have array structure of witch we don't know. Need to set value to it's nested value with check of existence of nested structure. It changes only given array keys.
Ome more example.
We have stait array with month, year and counts of entities within this date.
We need to recieve something like this:
Here is code for this:
Remove from array duplicated values
It needs simple to remove values witch duplicates. Here how we can do it.
Check is value in nested array
There is nested value with any structure. It checks is some value in given array including values in nested arrays.
Values can be changed before comparision:
Create new array with values from current array
It needs to create new list of values from any fixed list. The new list must contain random values.
It leaves keys in new array as it was in source array.
Concat arrays
Function array_merge
may act not right with associative arrays.
Example down next:
Concat action helps to do it right:
Computes the difference of arrays with additional index check
Compares array1 against array2 and more and returns the difference. It computes arrays recursively.
It may ignore some keys within result.
Check is array has only fixed keys
It checks source array if it has only this keys.
Create integer array with values not in sequence
There is an array with integer values we have. Values are mixed, not in order and can be duplicated. We can receive array with values witch were skipped.
Find max float value in array
It searches max float value in the given array. Each value is prepared by removing spaces.
Access array with path notation
Access to array value (more if array is nested) may require validation and check. Path helps make it easily.
Set value inside nested array:
Build array
MultilineTextToAssociatedArray
It creates array from text with lines as key-values pairs in it.
MultilineTextAsJsonToAssociatedArray
It creates array from text with lines as json-like key-values pairs in it.
MarkdownTableToArray
It creates array from Markdown table.
Read about format here
You can build not assoc array like this:
MultilineTextToNestedAssociatedArray
It creates array from text with lines as key-values pairs in it. Values are nested arrays.
StringExplode
It does simple string explode procedure with removing empty values or not.