PHP code example of algorithms / dijkstra

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

    

algorithms / dijkstra example snippets


    $dijkstra = new \PHPAlgorithms\Dijkstra(function (\PHPAlgorithms\Dijkstra\Creator $creator) {
        $creator->addPoint('start');

        $creator->addPoint('another one')
                ->addDoubleRelation($creator->getPoint(0), 10)
                ->addRelation($creator->addPoint(), 3);
    });

    [...]

    print_r($dijkstra->generate(0)); // \PHPAlgorithms\Dijkstra\Path object

    [...]

    print_r($dijkstra->generateAll()); // array of \PHPAlgorithms\Dijkstra\Path objects

    [...]

    print_r($pathObj->distance); // how is the path long
    print_r($pathObj->nodes); // all points in this path