PHP code example of best / dot-notation
1. Go to this page and download the library: Download best/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/ */
best / dot-notation example snippets
use Best\DotNotation;
$array = DotNotation::compact(array(
'my' => array(
'dotted' ==> array(
'key' => 'value'
)
)
));
// returns the dotted array:
array('my.dotted.key' => 'value');
// convert back to the other form:
$original = DotNotation::expand(['my.dotted.key' => 'value']);
$container = array('parent' => array('child' => '2'));
$childElement = \Best\DotNotation::get($container, 'parent.child');
// $childElement === '2' here
$container = array('parent' => array('child0', 'child1'));
$secondElement = \Best\DotNotation::get($container, 'parent.1');
// $secondElement === 'child1' here.
$container = array('parent0', 'parent1', 'parent2');
$thirdElement = \Best\DotNotation::get($container, 2);
// $thirdElement === 'parent2' here.
$container = array('parent0', array('child' => array('grandChild' => 'greatGrandChild'))));
$greatGrandChild = \Best\DotNotation::get($container, '1.child.grandChild')
// $greatGrandChild === 'greatGrandChild' here.
$container = array('my.dotted.key' => 'value');
$value = \Best\DotNotation::get($container, 'my\.dotted\.key'));
// equals: 'value'
use Best\DotNotation;
$container = ['movies' => [
[
'title' => 'Batman V. Superman - Dawn of Justice',
'director' => 'Zack Snyder'
'lead actor 1' => 'Henry Cavill'
'lead actor 2' => 'Ben Affleck'
'supporting actor 1' => 'Gal Gadot'
'supporting actor 2' => 'Jesse Eisenberg'
],
[
'title' => 'La La Land',
'director' => 'Damian Chazelle'
],
[
'title' => 'Justice League',
],
];
$zackSnyder = DotNotation::get($container, 'movies.0.director');
// $zackSnyder === 'Zack Snyder'
$null = DotNotation::getOrNull($container, 'movies.1.lead actor');
// $null === null
$jossWhedon = DotNotation::getOrDefault($container, 'movies.2.director', 'Joss Whedon');
// $jossWhedon === 'Joss Whedon'
$hasDirector = DotNotation::has($container, 'movies.2.director');
// $hasDirector === false
use Best\DotNotation;
$array = DotNotation::compact(array(
'my' => array(
'dotted' ==> array(
'key' => 'value'
)
)
));
// returns the dotted array:
array('my.dotted.key' => 'value');
$array = \Best\DotNotation::compact(array(
'my' => array(
'dotted' ==> array(
'key' => 'value'
)
)
));
// returns the dotted array:
array('my.dotted.key' => 'value');