PHP » GoLang |
login |
register |
about
|
getopt(PHP 4 >= 4.3.0, PHP 5, PHP 7) getopt — Gets options from the command line argument list Description
array getopt
( string
$options
[, array $longopts
[, int &$optind
]] )Parses options passed to the script. Parameters
The
Return Values
This function will return an array of option / argument pairs, or
Changelog
Examples
Example #1 getopt() example: The basics
<?php shell> php example.php -fvalue -h The above example will output: array(2) { ["f"]=> string(5) "value" ["h"]=> bool(false) }
Example #2 getopt() example: Introducing long options
<?php shell> php example.php -f "value for f" -v -a --required value --optional="optional value" --option The above example will output: array(6) { ["f"]=> string(11) "value for f" ["v"]=> bool(false) ["a"]=> bool(false) ["required"]=> string(5) "value" ["optional"]=> string(14) "optional value" ["option"]=> bool(false) }
Example #3 getopt() example: Passing multiple options as one
<?php shell> php example.php -aaac The above example will output: array(2) { ["a"]=> array(3) { [0]=> bool(false) [1]=> bool(false) [2]=> bool(false) } ["c"]=> bool(false) }
Example #4 getopt() example: Using
<?php shell> php example.php -a 1 -b 2 -- test The above example will output: array(1) { [0]=> string(4) "test" } |
more
Recently updated
more
Most requested
more
Last requests
|