PHP code example of firstred / php-dot-notation
1. Go to this page and download the library: Download firstred/php-dot-notation library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
firstred / php-dot-notation example snippets
$array['info']['home']['address'] = 'Kings Square';
echo $array['info']['home']['address'];
// Kings Square
$dot->set('info.home.address', 'Kings Square');
echo $dot->get('info.home.address');
$dot['info.home.address'] = 'Kings Square';
echo $dot['info.home.address'];
$dot = new \Adbar\Dot;
// With existing array
$dot = new \Adbar\Dot($array);
$dot = dot();
// With existing array
$dot = dot($array);
$dot->add('user.name', 'John');
// Equivalent vanilla PHP
if (!isset($array['user']['name'])) {
$array['user']['name'] = 'John';
}
$dot->add([
'user.name' => 'John',
'page.title' => 'Home'
]);
$values = $dot->all();
$dot->clear('user.settings');
// Equivalent vanilla PHP
$array['user']['settings'] = [];
$dot->clear(['user.settings', 'app.config']);
$dot->clear();
// Equivalent vanilla PHP
$array = [];
$dot->count('user.siblings');
$dot->count();
// Or use coun() function as Dot implements Countable
count($dot);
$dot->delete('user.name');
// ArrayAccess
unset($dot['user.name']);
// Equivalent vanilla PHP
unset($array['user']['name']);
$dot->delete([
'user.name',
'page.title'
]);
echo $dot->get('user.name');
// ArrayAccess
echo $dot['user.name'];
// Equivalent vanilla PHP < 7.0
echo isset($array['user']['name']) ? $array['user']['name'] : null;
// Equivalent vanilla PHP >= 7.0
echo $array['user']['name'] ?? null;
echo $dot->get('user.name', 'some default value');
$dot->has('user.name');
// ArrayAccess
isset($dot['user.name']);
$dot->has([
'user.name',
'page.title'
]);
$dot->isEmpty('user.name');
// ArrayAccess
empty($dot['user.name']);
// Equivalent vanilla PHP
empty($array['user']['name']);
$dot->isEmpty([
'user.name',
'page.title'
]);
$dot->isEmpty();
$dot->merge($array);
// Equivalent vanilla PHP
array_merge($originalArray, $array);
$dot->merge('user', $array);
// Equivalent vanilla PHP
array_merge($originalArray['user'], $array);
echo $dot->pull('user.name');
// Equivalent vanilla PHP < 7.0
echo isset($array['user']['name']) ? $array['user']['name'] : null;
unset($array['user']['name']);
// Equivalent vanilla PHP >= 7.0
echo $array['user']['name'] ?? null;
unset($array['user']['name']);
echo $dot->pull('user.name', 'some default value');
$items = $dot->pull();
$dot->push('users', 'John');
// Equivalent vanilla PHP
$array['users'][] = 'John';
$dot->push('John');
// Equivalent vanilla PHP
$array[] = 'John';
$dot->set('user.name', 'John');
// ArrayAccess
$dot['user.name'] = 'John';
// Equivalent vanilla PHP
$array['user']['name'] = 'John';
$dot->set([
'user.name' => 'John',
'page.title' => 'Home'
]);
$dot->setArray($array);
$dot->setReference($array);
echo $dot->toJson('user');
echo $dot->toJson();
$ composer