Gets options from the command line argument list
Syntax
getopt(string $short_options, array $long_options = [], int &$rest_index = null): array|false
Parameters
short_options
Each character in this string will be used as option characters and matched against options passed to the script starting with a single hyphen (-).
For example, an option string "x" recognizes an option -x. Only a-z, A-Z and 0-9 are allowed.
long_options
An array of options. Each element in this array will be used as option strings and matched against options passed to the script starting with two hyphens (--).
For example, an longopts element "opt" recognizes an option --opt.
rest_index
If the rest_index parameter is present, then the index where argument parsing stopped will be written to this variable.
Return
This function will return an array of option / argument pairs, or false on failure.
Note: The parsing of options will end at the first non-option found, anything that follows is discarded.
Examples
1 · short_options
<? $short_options = "f:"; $return = getopt($short_options); var_dump($return); ?>
2 · long_options
<? $short_options = "f:"; $long_options = array ( "required:", "optional::", ); $return = getopt($short_options, $long_options); var_dump($return); ?>
3 · rest_index
<? $short_options = "f:"; $long_options = array ( "required:", "optional::", ); $rest_index = null; $return = getopt($short_options, $long_options, $rest_index); var_dump($return); ?>