PHP code example of byjoby / flatrr

1. Go to this page and download the library: Download byjoby/flatrr 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/ */

    

byjoby / flatrr example snippets


// Instantiating FlatArrays can be done by passing them an array
// Keys in the initial array will be unflattened, for example the following
// yields a FlatArray containing ['foo'=>'bar','bar'=>['baz'=>'a','buz'=>'u']]
$f = new \Flatrr\FlatArray([
  'foo' => 'bar',
  'bar.baz' => 'a',
  'bar.buz' => 'u'
]);

// All of the following are equal to 'a'
$f['bar']['baz'];
$f['bar.baz'];
$f->get('bar.baz');

// Both of these work
$f['foo.bar'] = 'baz';
$f->set('foo.bar','baz');
// This does NOT work
$f['foo']['bar'] = 'baz';

$f = new \Flatrr\SelfReferencingFlatArray([
  'foo.bar' => 'baz',
  'foo.baz' => '${foo.bar}'
]);
// foo.baz will now always return the value of foo.bar
// echoes 'baz'
echo $f['foo.baz'];
// You can also get the "raw" value of a field using get()
// echoes '${foo.bar}'
echo $f->get('foo.baz');
// Variables can also be used as part of other strings
$f['a'] = 'foo.bar is: ${foo.bar}';
// echoes 'foo.bar is: baz'
echo $f['a'];
// Variables are resolved recursively
$f['b'] = 'foo.baz is: ${foo.baz}';
// echoes 'foo.baz is: baz'
echo $f['b'];