Download the PHP package best/dot-notation without Composer

On this page you can find all versions of the php package best/dot-notation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dot-notation

Dot Notation

This supports a dotted syntax similar to MongoDB's dot notation for creating and manipulating deeply nested arrays compactly in PHP. This notation is also used by other projects, such as Elasticsearch and CakePHP.

Installation

Overview

This package has a single class with static methods, \Best\DotNotation.

There are two main groups of methods: those that operate recursively across an entire array, and those that get/set values from such arrays.

Recursive methods

For the recursive methods, you can use expand and compact methods to convert the dots from the expanded form and the compact form, and these operations are inverses of each other:

Get/set values

For the other methods, pass an array as their first argument, and most then a "key path" as their second argument, that determines which keys on the array to operate on.

The key path can include dots to indicate subkeys of arrays to access.

For example, to access the key 'child' of the array key 'parent' on the variable $container, you would do:

You can also use numbers as keys. For example, to access the second array element in the key 'parent' of the variable $container, you would do this: (Note these are zero-indexed just like normal PHP arrays, so to get the second element, you specify .1 as the key):

You can also use bare integers:

Furthermore you can combine integer and string keys arbitrarily as well:

Escaping dot to include it in keys

If you want to include a literal dot inside a key name, you can escape it with a backslash.

Backslash is not treated as a special character in any other case, though. So you can use them in keys as long as it doesn't preceed a dot. Neither backslashes nor dots in values are transformed in any way, either.

Methods

Most of these methods require a valid key path. A valid key path is either an integer or non-empty string. Passing an invalid key path will result in a \Best\DotNotation\BadKeyPath exception.

Get Methods

get(array $array, string|int $keyPath): mixed

Get the value stored at the key path.

If any of the keys do not exist in the key path, this will throw a \Best\DotNotation\KeyNotFound exception.

getOrNull(array $array, string|int $keyPath): mixed

Get the value stored at the key path.

If any of the keys do not exist in the key path, this will return null.

getOrDefault(array $array, string|int $keyPath, mixed $defaultValue): mixed

Get the value stored at the key path.

If any of the keys do not exist in the key path, this will return the default value from the third argument.

has(array $array, string|int $keyPath): bool

Whether the array has a value at the key path.

Note that even if this value is null, this will still return true.

Set Methods

set(): array

Set the value

setAndOverride(array $array, string|int $keyPath): array

Set the path, and ignore any invalid intermediate keys, setting them to empty arrays along the way.

The new array with the key set is returned.

Remove Methods

remove()

Remove the value from the key path if it exists. A \Best\DotNotation\KeyNotFound exception is thrown if any of the keys in the key path do not exist.

removeIfExists(array $array, string|int $keyPath)

Remove the value from the key path if it exists. No exception is thrown if the key path does not exist.

The new array with the key removed is returned.

Recursive Methods

expand(array $dottedArray): array

Recursively expand the dots inside the keys into new arrays. Returns the newly expanded array.

If any inconsistent keys are detected (some keys are defined as scalars in some keys and are implicitly arrays in other keys), a \Best\DotNotation\InconsistentKeyTypes exception will be thrown.

compact(array $array): array

Compact the array into a dotted array, with keys, suitable for passing to expand().

For example:

compactWithIntegerKeys(array $array): array

Compact the array as in compact(), but also compact integer keys, so that the array will be as flat as possible.

For example,


All versions of dot-notation with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package best/dot-notation contains the following files

Loading the files please wait ....