https://github.com/enzyme/freckle
A collection of dot-based information retrieval helpers... wuh?
https://github.com/enzyme/freckle
Last synced: 8 months ago
JSON representation
A collection of dot-based information retrieval helpers... wuh?
- Host: GitHub
- URL: https://github.com/enzyme/freckle
- Owner: enzyme
- License: mit
- Created: 2016-04-03T03:04:50.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-03T05:53:36.000Z (about 10 years ago)
- Last Synced: 2025-05-14T18:54:52.040Z (about 1 year ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://travis-ci.org/enzyme/freckle)
[](https://coveralls.io/github/enzyme/freckle?branch=master)
[](https://scrutinizer-ci.com/g/enzyme/freckle/?branch=master)
Freckle is a collection of information accessors. It allows you to traverse and get the values in arrays and other collection types using dot separated paths. For example, getting the value in a multi-dimensional-associative array for `users.bob456.name`, given the array:
```php
$array = [
'users' => [
'jane123' => ['name' => 'Jane Foo'],
'bob456' => ['name' => 'Bob Foo'],
]
];
```
would return the value of `Bob Foo`. Pretty straight forward hey?
# Installation
```bash
composer require enzyme/freckle
```
# Usage
Getting a value from a simple collection.
```php
use Enzyme\Freckle\Dot;
$array = [
'users' => [
'jane123' => ['name' => 'Jane Foo'],
'bob456' => ['name' => 'Bob Foo'],
]
];
$dot = new Dot;
$full_name = $dot->get($array, 'users.bob456.name'); // returns "Bob Foo".
```
Getting a value from a simple collection with numeric keys.
```php
use Enzyme\Freckle\Dot;
$array = [
'users' => [
0 => [
'jane123' => ['name' => 'Jane Foo'],
],
1 => [
'bob456' => ['name' => 'Bob Foo'],
]
]
];
$dot = new Dot;
$full_name = $dot->get($array, 'users.bob456.name'); // returns "Bob Foo".
```
In the event that a collection has numeric keys or supports multiple entries with the same key name, only the first result found will ever be returned.
If no value can be found, `null` will be returned instead. **Be careful though** if you're checking against the null value for success as you may get false positives if an actual value was found, but that value happens to be `null`.
# Contributing
Please see `CONTRIBUTING.md`
# License
MIT - Copyright (c) 2015 Tristan Strathearn, see `LICENSE`