1. Go to this page and download the library: Download phgraph/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/ */
phgraph / graph example snippets
use PHGraph\Graph;
use PHGraph\Search\BreadthFirst;
…
$graph = new Graph;
$columbus = $graph->newVertex([
'name' => 'Columbus',
]);
$cleveland = $graph->newVertex([
'name' => 'Cleveland',
]);
$cincinnati = $graph->newVertex([
'name' => 'Cincinnati',
]);
$columbus->createEdge($cleveland);
$columbus->createEdge($cincinnati);
$search = new BreadthFirst($cincinnati);
if ($search->hasVertex($cleveland)) {
echo "We can get from Cincinnati to Cleveland\n";
} else {
echo "We can’t get from Cincinnati to Cleveland\n";
}
use PHGraph\Graph;
use PHGraph\GraphViz\GraphViz;
…
$graph = new Graph;
$columbus = $graph->newVertex([
'name' => 'Columbus',
]);
$cleveland = $graph->newVertex([
'name' => 'Cleveland',
]);
$cincinnati = $graph->newVertex([
'name' => 'Cincinnati',
]);
$columbus->createEdge($cleveland);
$columbus->createEdge($cincinnati);
$graphviz = new GraphViz($graph);
// open the image on your system
$graphviz->display();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.