Arrays Component contains methods that can be useful when working with arrays.
Installs: 4 956
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.0
Requires (Dev)
- doctrine/coding-standard: 7.0.2
README
Installation
With Composer:
composer require flextype-components/arrays
Usage
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. |
Method: 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::set($array, 'movies.the-thin-red-line.title', 'The Thin Red Line');
Method: 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::get($array, 'movies.the-thin-red-line.title')
Method: Arrays::delete()
Deletes an array value using "dot notation".
Arrays::delete($array, 'movies.the-thin-red-line');
Method: Arrays::has()
Checks if the given dot-notated key exists in the array.
if (Arrays::has($array, 'movies.the-thin-red-line')) { // Do something... }
Method: Arrays::dot()
Flatten a multi-dimensional associative array with dots.
$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.
$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) Copyright (c) 2020 Sergey Romanenko