PHP code example of hexlet / graphs

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

    

hexlet / graphs example snippets




use function Php\Graphs\graphs\makeJoints;
use function Php\Graphs\graphs\buildTreeFromLeaf;
use function Php\Graphs\graphs\sortJoints;

$tree = ['B', [
    ['D'],
    ['A', [
        ['C', [
            ['F'],
            ['E'],
        ]],
    ]],
]];

$joints = makeJoints($tree);
$transformed = buildTreeFromLeaf($joints, 'C');
// ['C', [
//     ['F'],
//     ['E'],
//     ['A', [
//         ['B', [
//             ['D'],
//         ]],
//     ]],
// ]];

sortTree($transformed);
// ['C', [
//     ['A', [
//         ['B', [
//             ['D'],
//         ]],
//     ]],
//     ['E'],
//     ['F'],
// ]];