PHP code example of ashleydawson / canonically-flatten-tree

1. Go to this page and download the library: Download ashleydawson/canonically-flatten-tree 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/ */

    

ashleydawson / canonically-flatten-tree example snippets




 = [
    "gamma", 
    [
        "alpha", 
        [
            "beta",
        ],
    ], 
    [
        [
            [
                "delta",
            ]
        ]
    ],
];

$list = \AshleyDawson\CanonicallyFlattenTree\canonically_flatten_scalar_tree($tree);

print_r($list);

/*
Where output is:

Array
(
    [0] => alpha
    [1] => beta
    [2] => delta
    [3] => gamma
)
*/



is will produce an invalid argument exception stating the nature of the type failure and at what level
// In this case we're asserting that all tree nodes must be of type "string"
try {
    \AshleyDawson\CanonicallyFlattenTree\canonically_flatten_scalar_tree(['alpha', [8]], 'string');
} catch (\InvalidArgumentException $e) {
    var_dump($e);
}