PHP code example of clue / graph

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

    

clue / graph example snippets




h = new Graphp\Graph\Graph();

// create some cities
$rome = $graph->createVertex(array('name' => 'Rome'));
$madrid = $graph->createVertex(array('name' => 'Madrid'));
$cologne = $graph->createVertex(array('name' => 'Cologne'));

// build some roads
$graph->createEdgeDirected($cologne, $madrid);
$graph->createEdgeDirected($madrid, $rome);
// create loop
$graph->createEdgeDirected($rome, $rome);

foreach ($rome->getVerticesEdgeFrom() as $vertex) {
    echo $vertex->getAttribute('name') . ' leads to Rome' . PHP_EOL;
    // result: Madrid and Rome itself lead to Rome
}