fnayou / dotted
php library to access multidimensional arrays
Installs: 3 092
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 1
Open Issues: 0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.3
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.8.2
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.0
This package is auto-updated.
Last update: 2024-10-29 03:53:33 UTC
README
Dotted is a PHP library to manage multidimensional arrays !
It will help you checking, accessing or inserting values of an array.
Installation
use Composer to install dotted
library :
$ php composer.phar require fnayou/dotted
or download the latest 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 use Fnayou\Dotted; $content = [ 'keyOne' => '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
License
Please see License File for more information.