https://github.com/flextype-components/arrays
Arrays Component contains methods that can be useful when working with arrays.
https://github.com/flextype-components/arrays
array component flextype flextype-component php
Last synced: 5 months ago
JSON representation
Arrays Component contains methods that can be useful when working with arrays.
- Host: GitHub
- URL: https://github.com/flextype-components/arrays
- Owner: flextype-components
- License: mit
- Created: 2015-10-04T22:50:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-24T14:55:24.000Z (almost 6 years ago)
- Last Synced: 2025-09-29T05:42:22.345Z (9 months ago)
- Topics: array, component, flextype, flextype-component, php
- Language: PHP
- Homepage: http://components.flextype.org
- Size: 41 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Arrays Component
### Installation
With [Composer](https://getcomposer.org):
```
composer require flextype-components/arrays
```
### Usage
```php
use Flextype\Component\Arrays;
```
### Methods
| Method | Description |
|---|---|
| `Arrays::set()` | Set an array item to a given value using "dot" notation. If no key is given to the method, the entire array will be replaced. |
| `Arrays::get()` | Returns value from array using "dot notation". If the key does not exist in the array, the default value will be returned instead. |
| `Arrays::delete()` | Deletes an array value using "dot notation". |
| `Arrays::has()` | Checks if the given dot-notated key exists in the array. |
| `Arrays::dot()` | Flatten a multi-dimensional associative array with dots. |
| `Arrays::undot()` | Expands a dot notation array into a full multi-dimensional array. |
Set an array item to a given value using "dot" notation. If no key is given to the method, the entire array will be replaced.
```php
Arrays::set($array, 'movies.the-thin-red-line.title', 'The Thin Red Line');
```
Returns value from array using "dot notation".
If the key does not exist in the array, the default value will be returned instead.
```php
Arrays::get($array, 'movies.the-thin-red-line.title')
```
#### Method: `Arrays::delete()`
Deletes an array value using "dot notation".
```php
Arrays::delete($array, 'movies.the-thin-red-line');
```
Checks if the given dot-notated key exists in the array.
```php
if (Arrays::has($array, 'movies.the-thin-red-line')) {
// Do something...
}
```
Flatten a multi-dimensional associative array with dots.
```php
$array = [
'movies' => [
'the_thin_red_line' => [
'title' => 'The Thin Red Line',
'directed_by' => 'Terrence Malick',
'produced_by' => 'Robert Michael, Geisler Grant Hill, John Roberdeau',
'decription' => 'Adaptation of James Jones autobiographical 1962 novel, focusing on the conflict at Guadalcanal during the second World War.',
],
],
];
$newArray = Arrays::dot($array);
```
#### Method: `Arrays::undot()`
Expands a dot notation array into a full multi-dimensional array.
```php
$array = [
'movies.the_thin_red_line.title' => 'The Thin Red Line',
'movies.the_thin_red_line.directed_by' => 'Terrence Malick',
'movies.the_thin_red_line.produced_by' => 'Robert Michael, Geisler Grant Hill, John Roberdeau',
'movies.the_thin_red_line.decription' => 'Adaptation of James Jones autobiographical 1962 novel, focusing on the conflict at Guadalcanal during the second World War.',
];
$newArray = Arrays::undot($array);
```
### License
[The MIT License (MIT)](https://github.com/flextype-components/arrays/blob/master/LICENSE.txt)
Copyright (c) 2020 [Sergey Romanenko](https://github.com/Awilum)