PHP code example of gryfoss / odds
1. Go to this page and download the library: Download gryfoss/odds 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/ */
gryfoss / odds example snippets
use GryfOSS\Odds\OddsFactory;
$factory = new OddsFactory();
// Create from string decimal (secure, precise)
$odds = $factory->fromDecimal('2.50');
echo $odds->getDecimal(); // "2.50"
echo $odds->getFractional(); // "3/2"
echo $odds->getMoneyline(); // "+150"
echo $odds->getProbability(); // 40 (integer percentage)
$factory = new OddsFactory();
// From decimal
$odds = $factory->fromDecimal('1.75');
// From fractional
$odds = $factory->fromFractional(3, 4);
// From moneyline
$odds = $factory->fromMoneyline('-133');
// From fixed precision integer (advanced usage)
$odds = $factory->fromFixedPrecision(250); // Represents 2.50
use GryfOSS\Odds\Utils\OddsLadder;
$oddsLadder = new OddsLadder();
$factory = new OddsFactory($oddsLadder);
$odds = $factory->fromDecimal('2.00');
echo $odds->getFractional(); // Uses odds ladder lookup
use GryfOSS\Odds\Utils\OddsLadder;
class MyCustomLadder extends OddsLadder
{
protected function getLadder(): array
{
return [
'1.50' => 'evens',
'2.00' => '1/1',
'3.00' => '2/1',
];
}
}
$factory = new OddsFactory(new MyCustomLadder());
$odds = $factory->fromDecimal('1.90');
echo $odds->getFractional(); // "evens"
$factory = new OddsFactory();
// Create from already prepared integer (2.50 = 250)
$odds = $factory->fromFixedPrecision(250);
echo $odds->getDecimal(); // "2.50"
echo $odds->getFixedPrecisionOdds(); // 250
// Useful for database storage or API responses
$integerOdds = $odds->getFixedPrecisionOdds(); // Store as integer
$restoredOdds = $factory->fromFixedPrecision($integerOdds); // Restore later