PHP code example of reeyanto / moora

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

    

reeyanto / moora example snippets




use Reeyanto\Moora\Moora;

$moora = new Moora();

use Riyanto\Moora\Moora;

$moora = new Moora();

/**
 * Tambah kriteria
 */
$moora
    ->addCriteria('price', 0.3, 'cost')
    ->addCriteria('quality', 0.4, 'benefit')
    ->addCriteria('features', 0.3, 'benefit');

/**
 * Tambah alternatif
 */
$moora
    ->addAlternative('Produk A', [
        'price' => 300,
        'quality' => 80,
        'features' => 70,
    ])
    ->addAlternative('Produk B', [
        'price' => 250,
        'quality' => 75,
        'features' => 85,
    ])
    ->addAlternative('Produk C', [
        'price' => 400,
        'quality' => 90,
        'features' => 95,
    ]);

/**
 * Hitung hasil
 */
$result = $moora->calculate();

print_r($result);

Array
(
    [0] => Array
        (
            [alternative] => Produk C
            [score] => 0.4012
            [rank] => 1
        )

    [1] => Array
        (
            [alternative] => Produk B
            [score] => 0.3551
            [rank] => 2
        )

    [2] => Array
        (
            [alternative] => Produk A
            [score] => 0.3014
            [rank] => 3
        )
)