Dot is a tiny library and implements array dot notation for PHP written by Selvin Ortiz
- PHP 7.1+
- Composer and selvinortiz/dot
composer require selvinortiz/dotsh spec.shTo use Dot after proper installation, just autoload it, use it, and call methods on it:)
$input = [
'name' => [
'first' => 'Brad',
'last' => 'Bell',
],
'spouse' => [
'name' => [
'first' => 'Brandon',
'last' => 'Kelly'
],
'mood' => 'Happy',
'age' => '75',
],
'mood' => 'Angry',
'age' => 25,
];
Dot::has($input, 'spouse');
// true
Dot::has($input, 'mistress.relationship');
// false
Dot::get($input, 'spouse.name.last');
// 'Kelly'
Dot::get($input, 'spouse');
/*
[
'name' => [
'first' => 'Brandon',
'last' => 'Kelly'
],
'mood' => 'Happy',
'age' => '75'
]
*/
Dot::set($input, 'spouse.name.last', 'Bell');
/* $input will be mutated with a changed value
[
'name' => [
'first' => 'Brad',
'last' => 'Bell',
],
'spouse' => [
'name' => [
'first' => 'Brandon',
'last' => 'Bell'
],
'mood' => 'Happy',
'age' => '75',
],
'mood' => 'Angry',
'age' => 25,
];
*/
Dot::delete($input, 'spouse.mood');
/* $input will be mutated with a key/value deleted
[
'name' => [
'first' => 'Brad',
'last' => 'Bell',
],
'spouse' => [
'name' => [
'first' => 'Brandon',
'last' => 'Bell'
]
'age' => '75',
],
'mood' => 'Angry',
'age' => 25,
];
*/Dot has a very small API and hoping to keep it small and to the point.
Returns whether or not
$arrhas$key. Put another way,$keyexists in$arr
Returns the value found in
$arrby$keyor$defaultprovided
Mutates the
$arrby adding a new$keywith$valueprovided
Mutates the
$arrby delete$keyand its associated value if found
Dot wants to be friendly to first time contributors. Just follow the steps below and if you have questions along the way, please reach out.
- Fork it!
- Create your
bugfixorfeaturebranch - Commit and push your changes
- Submit a pull request
Dot is open source software licensed under the MIT License



