PHP code example of nafisc / parameterparser

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

    

nafisc / parameterparser example snippets


// Initialize a new Cluster
$parameters = new Cluster();

// Add a Parameter to the Cluster
$parameter = parameter('-', 'name', function ($name) {
    return $name;
});

$parameter->setRequired(true)
          ->setDescription('Your name.');

$parameters->add($parameter);

// Create a new Parser using the Cluster
$parser = new Parser($argv, $parameters);

// Parse the parameters using the Parser.
$results = $parser->parse();

// Verify that the parameters were valid after parsing.
if (! $parser->isValid()) {

    // Since it was not valid, output usage.
    $parameters->printFullUsage(
        "Parameter Parser",
        "An advanced parameter parser for PHP",
        "v1.0.0"
    );

} else {

    // Retrieve the name from the results
    $name = $results['name'];

    // Output the name
    echo 'Your name is ' . $name . PHP_EOL;

}