Download the PHP package adbario/php-dot-notation without Composer
On this page you can find all versions of the php package adbario/php-dot-notation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download adbario/php-dot-notation
More information about adbario/php-dot-notation
Files in adbario/php-dot-notation
Package php-dot-notation
Short Description PHP dot notation access to arrays
License MIT
Homepage https://github.com/adbario/php-dot-notation
Informations about the package php-dot-notation
About Dot
Dot provides an easy access to arrays of data with dot notation in a lightweight and fast way. Inspired by Laravel Collection.
Dot implements PHP's ArrayAccess interface and Dot object can also be used the same way as normal arrays with additional dot notation.
Examples
With Dot you can change this regular array syntax:
to this (Dot object):
or even this (ArrayAccess):
Install
Install the latest version using Composer:
Usage
Create a new Dot object:
You can also use a helper function to create the object:
All methods not returning a specific value returns the Dot object for chaining:
Methods
Dot has the following methods:
- add()
- all()
- clear()
- count()
- delete()
- flatten()
- get()
- has()
- isEmpty()
- merge()
- mergeRecursive()
- mergeRecursiveDistinct()
- pull()
- push()
- replace()
- set()
- setArray()
- setReference()
- toJson()
add()
Sets a given key / value pair if the key doesn't exist already:
Multiple key / value pairs:
all()
Returns all the stored items as an array:
clear()
Deletes the contents of a given key (sets an empty array):
Multiple keys:
All the stored items:
count()
Returns the number of items in a given key:
Items in the root of Dot object:
delete()
Deletes the given key:
Multiple keys:
flatten()
Returns a flattened array with the keys delimited by a given character (default "."):
get()
Returns the value of a given key:
Returns a given default value, if the given key doesn't exist:
has()
Checks if a given key exists (returns boolean true or false):
Multiple keys:
isEmpty()
Checks if a given key is empty (returns boolean true or false):
Multiple keys:
Checks the whole Dot object:
merge()
Merges a given array or another Dot object:
Merges a given array or another Dot object with the given key:
mergeRecursive()
Recursively merges a given array or another Dot object:
Recursively merges a given array or another Dot object with the given key:
mergeRecursiveDistinct()
Recursively merges a given array or another Dot object. Duplicate keys overwrite the value in the original array (unlike mergeRecursive(), where duplicate keys are transformed into arrays with multiple values):
Recursively merges a given array or another Dot object with the given key. Duplicate keys overwrite the value in the original array.
pull()
Returns the value of a given key and deletes the key:
Returns a given default value, if the given key doesn't exist:
Returns all the stored items as an array and clears the Dot object:
push()
Pushes a given value to the end of the array in a given key:
Pushes a given value to the end of the array:
replace()
Replaces the values with values having the same keys in the given array or Dot object:
Replaces the values with values having the same keys in the given array or Dot object with the given key:
replace()
is not recursive.
set()
Sets a given key / value pair:
Multiple key / value pairs:
setArray()
Replaces all items in Dot object with a given array:
setReference()
Replaces all items in Dot object with a given array as a reference and all future changes to Dot will be made directly to the original array:
toJson()
Returns the value of a given key as JSON:
Returns all the stored items as JSON:
Contributing
Pull Requests
- Fork the Dot repository
- Create a new branch for each feature or improvement
- Send a pull request from each feature branch to the 3.x branch
It is very important to separate new features or improvements into separate feature branches, and to send a pull request for each branch. This allows me to review and pull in new features or improvements individually.
Style Guide
All pull requests must adhere to the PSR-12 standard.
Unit Testing
All pull requests must be accompanied by passing unit tests and complete code coverage. Dot uses PHPUnit for testing.
Static Analysis
All pull requests must pass static analysis using PHPStan.
License
MIT license
All versions of php-dot-notation with dependencies
ext-json Version *