PHP code example of windwalker / structure

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

    

windwalker / structure example snippets

 php
$structure->get('foo');

// Get a non-exists value and return default
$structure->get('foo', 'default');

// OR

$structure->get('foo') ?: 'default';
 php
$json = '{
	"parent" : {
		"child" : "Foo"
	}
}';

$structure = new Structure($json);

$structure->get('parent.child'); // return 'Foo'

$structure->set('parent.child', $value);
 php
$structure->setSeparator('/');

$data = $structure->get('foo/bar');
 php
// Set a value in the structure.
$structure['foo'] = 'bar';

// Get a value from the structure;
$value = $structure['foo'];

// Check if a key in the structure is set.
if (isset($structure['foo']))
{
	echo 'Say bar.';
}
 php
$structure1->merge($structure2, false); // Set param 2 to false that Structure will only merge first level
 php
$structure->mergeTo('foo.bar', $anotherStructure);
 php
$structure->toString();

$structure->toString('xml');

$structure->toString('ini');
 php
$array = array(
    'flower' => array(
        'sunflower' => 'light',
        'sakura' => 'samurai'
    )
);

$structure = new Structure($array);

// Make data to one dimension

$flatted = $structure->flatten();

print_r($flatted);
 php
use Windwalker\Structure\StructureHelper;

StructureHelper::loadFaile($file, $format); // File to array
StructureHelper::loadString($string, $format); // String to array
StructureHelper::toString($array, $format); // Array to string

// Use format class
$json = StructureHelper::getFormatClass('json'); // Get JsonFormat
$string = $json::structToString($array);