https://github.com/fnayou/dotted
php library to access multidimensional arrays
https://github.com/fnayou/dotted
array library multidimensional php
Last synced: about 1 year ago
JSON representation
php library to access multidimensional arrays
- Host: GitHub
- URL: https://github.com/fnayou/dotted
- Owner: fnayou
- License: mit
- Created: 2017-06-19T14:43:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-10-30T19:45:08.000Z (over 3 years ago)
- Last Synced: 2024-11-01T13:46:41.806Z (over 1 year ago)
- Topics: array, library, multidimensional, php
- Language: PHP
- Homepage: https://github.com/fnayou/dotted
- Size: 28.3 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Dotted
======

[](https://scrutinizer-ci.com/g/fnayou/dotted/?branch=master)
[](https://packagist.org/packages/fnayou/dotted)
[](https://drone.aymen.fr/fnayou/dotted)
**Dotted** is a PHP library to manage *multidimensional arrays* !
It will help you *checking*, *accessing* or *inserting* values of an array.
## Installation
use [Composer][link-composer] to install `dotted` library :
```shell
$ php composer.phar require fnayou/dotted
```
or [download the latest release][link-release] and include `src/Dotted.php` in your project.
## Compatibility
after the last changes. **Dotted** is only compatible with `>= PHP 7.4`
for older versions, please use tag `1.x.x`
## Usage
first, you create `dotted` object by passing the `array` content.
next you can *check*, *access* or *insert* values with ease.
```php
'valueOne',
'keyTwo' => [
'keyThree' => 3,
'keyFour' => false,
'keyFive' => [
true,
'valueFive',
5,
]
]
];
$dotted = new Dotted($content);
// or
$dotted = Dotted::create($content);
// check if values exist
echo $dotted->has('keyOne'); // output : true
echo $dotted->has('keyTwo.keySix'); // output : false
// access values
echo $dotted->get('keyOne'); // output : valueOne
echo $dotted->get('keyTwo.keyThree'); // output : 3
echo $dotted->get('keyTwo.keyFive.0'); // output : true
// access non-existent value
echo $dotted->get('keyTwo.keySix'); // output : null
// access value with default value
echo $dotted->get('keyTwo.keySix', 'defaultValue'); // output : defaultValue
// insert value
$dotted->set('keyTwo.keySix', 'valueSix');
echo $dotted->get('keyTwo.keySix'); // output : valueSix
// insert value with override
$dotted->set('keyTwo.keySix', 6); // output : 6
// access values (array content)
$dotted->getValues();
/** output :
array:2 [▼
"keyOne" => "valueOne"
"keyTwo" => array:3 [▼
"keyThree" => 3
"keyFour" => false
"keyFive" => array:3 [▼
0 => true
1 => "valueFive"
2 => 5
]
]
]
*/
// access flatten values
$dotted->flatten();
/** output :
array:6 [▼
"keyOne" => "valueOne"
"keyTwo.keyThree" => 3
"keyTwo.keyFour" => false
"keyTwo.keyFive.0" => true
"keyTwo.keyFive.1" => "valueFive"
"keyTwo.keyFive.2" => 5
]
*/
```
## Credits
[Aymen FNAYOU][link-author]
## License
 Please see [License File](LICENSE.md) for more information.
[link-author]: https://github.com/fnayou
[link-composer]: https://getcomposer.org/
[link-release]: https://github.com/fnayou/dotted/releases