getopt

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);

?>

			
		

assert

assert_options

cli_get_process_title

cli_set_process_title

dl

extension_loaded

gc_collect_cycles

gc_disable

gc_enable

gc_enabled

gc_mem_caches

gc_status

get_cfg_var

get_current_user

get_defined_constants

get_extension_funcs

get_include_path

get_included_files

get_loaded_extensions

get_required_files

get_resources

getenv

getlastmod

getmygid

getmyinode

getmypid

getmyuid

getrusage

ini_alter

ini_get

ini_get_all

ini_restore

ini_set

memory_get_peak_usage

memory_get_usage

memory_reset_peak_usage

php_ini_loaded_file

php_ini_scanned_files

php_sapi_name

php_uname

phpcredits

phpinfo

phpversion

putenv

set_include_path

set_time_limit

sys_get_temp_dir

version_compare

zend_thread_id

zend_version

PHP

Home Menu