PHP code example of frvaillant / dichotomic

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

    

frvaillant / dichotomic example snippets


use Dichotomic\Resolver;

class BirdAlgo extends Resolver

{
    private $result;

    protected $algo = [
        'hasHookedBeak' => [
            true  => [
                'isNocturnal' => [
                    true => [
                        'hasFeatherCrests' => [
                            true => 'ended:hibou',
                            false => 'ended:chouette'
                        ]
                    ],
                    false => [
                        'hasPointedWings' => [
                            true => 'ended:faucon',
                            false => 'ended:aigle'
                        ]
                    ]
                ]
            ],
            false => 'ended:null'
        ]
    ];
}

    /**
    * NOTE : all the methods listed as key in $algo array must be implemented below
     */
    protected function hasHookedBeak(): bool
    {
        return true;
    }

    protected function isNocturnal(): bool
    {
        return true;
    }

    protected function hasFeatherCrests(): bool
    {
        return false;
    }

    protected function hasPointedWings(): bool
    {
        return true;
    }

    protected function ended($result): void
    {
        $this->result = $result;
    }

    public function getResult()
    {
        return $this->result;
    }
 
$algo = new BirdAlgo();
$algo->execute();
echo $algo->getResult();