1. Go to this page and download the library: Download kristos80/opton 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/ */
/**
*
* @param array|object|string $name
* The name of the option/key to be found
* @param array|object|NULL $pool
* The pool of data to search within
* @param mixed|NULL $default
* Default value if nothing is found
* @param array|object|NULL $acceptedValues
* Array of accepted values. It affects even the `default` value
* @return mixed|NULL
*/
static function get($name, $pool = array(), $default = NULL, array $acceptedValues = array()) {
Kristos80\Opton\Opton;
$options = array(
'optionName' => 'optionValue',
);
$acceptedValues = array(
'optionValue',
);
// prints 'optionValue'
echo Opton::get('optionName', $options, NULL, $acceptedValues);
echo "\r\n";
// prints `NULL`
echo Opton::get('optionNameNonExistent', $options);
echo "\r\n";
// prints 'defaultValue'
echo Opton::get('optionNameNonExistent', $options, 'defaultValue');
echo "\r\n";
// prints `NULL`
echo Opton::get('optionNameNonExistent', $options, 'defaultValue', $acceptedValues);
echo "\r\n";
// `name` can be an array
// prints 'optionValue'
echo Opton::get(array(
'optionName',
'optionNameNonExistent',
), $options);
echo "\r\n";
// Use a single configuration array with keys:
// `name`
// `pool`
// `default`
// `acceptedValues`
//
// prints 'defaultValue'
echo Opton::get(array(
'name' => 'optionNameNonExistent',
'pool' => $options,
'default' => 'defaultValue',
));
echo "\r\n";