PHPackages                             ryanwhowe/dot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ryanwhowe/dot

Abandoned → [axetools/dot](/?search=axetools%2Fdot)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

ryanwhowe/dot
=============

A PHP library to access and Set values in an array using dot notation or any other separator

v3.1.0(2y ago)0223↓100%[2 issues](https://github.com/ryanwhowe/Dot/issues)MITPHPPHP ^8.0

Since Jun 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ryanwhowe/Dot)[ Packagist](https://packagist.org/packages/ryanwhowe/dot)[ RSS](/packages/ryanwhowe-dot/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (12)Used By (0)

ryanwhowe/dot
=============

[](#ryanwhowedot)

 **A PHP library to access and set array values using dot notation or any other key separator.**

 [![Source Code](https://camo.githubusercontent.com/2f70f8a45237029659c180d696fa7df1b1f85cf097349e01f637dd7cc7bfaa9d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d7279616e77686f77652f646f742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/ryanwhowe/dot) [![PHP Programming Language](https://camo.githubusercontent.com/49198d28f7c5711460407e7e61cc339416ffc17c0ec24be6b8513079b6af39cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7279616e77686f77652f646f742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d253233383839324246)](https://php.net) [![Read License](https://camo.githubusercontent.com/4c7489d845a037c3abe0cc0e5e7aae63e6bcf921620a5bba6e0aebd7a9d062c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7279616e77686f77652f646f742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6461726b6379616e)](https://github.com/ryanwhowe/dot/blob/3.x/LICENSE) [![Build Status](https://camo.githubusercontent.com/eaf782e19623f94fdbcf080e8d4a2178a0cb1fabb36b0b1ea3d2af77a2d4029e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7279616e77686f77652f646f742f7068702e796d6c3f6272616e63683d312e78266c6f676f3d676974687562267374796c653d666c61742d737175617265)](https://github.com/ryanwhowe/dot/actions/workflows/php.yml)

Q: There are quite a few 'dot' projects that exist on Packagist, what is different about this one?

> Every other 'dot' project requires you to create a copy of your data and instantiate a new class, this project uses light weight static methods to access and modify your existing arrays without the need to create a second copy of the data.

> The other advantage that this has over many other implementations is that you can select an alternative key separator than a '.' which is necessary if you have key values that contain '.' characters in them.

Q: Why add this to Packagist?

> This package has been used on several of my projects both personally and professionally, and I am tired of copying the class from one project to another. If my teams and I get usage out of this project, I wanted to share it to allow anyone else who this could help use it as well.

Compatability
-------------

[](#compatability)

If you are still working on php 5.6, please use the `1.x` branch, I will try and keep that patched with any non-breaking changes and/or bug fixes that are found. But with [Semantic Versioning](https://semver.org/spec/v2.0.0.html) there will be no backwards incompatible releases made to the branch and there are no plans for another major version that supports php 5.6. I will however try and backport any major functionality or feature additions to the `1.x` branch.

The `2.x` branch has the php ^7.1 support if you require that for your project. As with the `1.x` branch I will keep that patched with any non-breaking changes and/or bugs that are found.

> Warning: When you have xDebug enabled the recursion depth is set to 100, however the PHP [manual](https://www.php.net/manual/en/functions.user-defined.php#example-149) advises against doing 100-200 recursion levels as it can smash the stack and cause termination of the current script. This class utilizes recursion to traverse the array. If you need to traverse an array with depth deeper than 100 levels this likely is the wrong tool to utilize.

Installation
------------

[](#installation)

The preferred method of installation is via [Composer](http://getcomposer.org/). Run the following command to install the package and add it as a requirement to your project's `composer.json`:

```
composer require ryanwhowe/dot
```

Usage
-----

[](#usage)

The Dot class contains static methods to facilitate the safe access, setting, unsetting and counting of array data in php.

### `Dot::has()`

[](#dothas)

The `Dot::has()` checks to see if there is a value in the search array for the search key. This method utilizes recursion to traverse the array.

There is a globally available `dotHas()` function, that wraps the `Dot::has()` static method included in the autoloader.

#### Description

[](#description)

```
Dot::has(array $searchArray, string $searchKey, string $delimiter = '.'): bool

```

#### Parameters

[](#parameters)

searchArrayThe array that will be searched for the provided key valuesearchKeyThe delimited key that will be searched for in the provided searchArray. If the array does not have string keys number strings can be used instead to access the appropriate position in the arraydelimiterThe key delimiter can be specified, this is needed when there are '.' values contained within the expected array keys already#### Return Values

[](#return-values)

The method returns `true` if found and `false` if not.

#### Examples

[](#examples)

##### Example #1 simple key value lookup

[](#example-1-simple-key-value-lookup)

```
