##$argv or $argc
$argv is an array containing the arguments passed to the current script when run from the command line. $argv[0] is the script file name.
$argc contains the number of arguments passed to the current script when run from the command line. The script's filename is always passed as an argument to the current script, so the minimum value of $argc is 1.
The two variables are only available when register_argc_argv is turned on.
Note: $argv and $argc must be declared as global variables inside class methods or functions
<?<span>php </span><span>class</span><span> A { </span><span>public</span> <span>static</span> <span>function</span><span> b() { </span><span>var_dump</span>(<span>$argv</span><span>); </span><span>var_dump</span>(<span>isset</span>(<span>$argv</span><span>)); } } A</span>::b();
<?<span>php printarg(); </span><span>function</span><span> printarg(){ </span><span>global</span> <span>$argc</span>,<span>$argv</span><span>; </span><span>print</span>(<span>$argc</span>."个参数\n"<span>); </span><span>print_r</span>(<span>$argv</span><span>); }</span>
##getopt
array getopt ( string $options [, array $longopts ] )
options Each character in this string will be treated as an option character, matching the options passed to the script. Begins with a single hyphen (-). For example, an option string "x" identifies an option -x. Only a-z, A-Z and 0-9 are allowed. longopts Array of options. Each element in this array will be treated as an options string, matching the options passed to the script with two hyphens (--). For example, the long option element "opt" identifies an option --opt.
options may contain the following elements:
1. A single character (does not accept a value)
2. A character followed by a colon (this option requires a value)
3. Followed by two characters colon characters (the value of this option is optional) The value of the
option is the first parameter after the string. It doesn't mind if there are spaces before the value.
Return value:
This function returns an option/parameter pair, and returns FALSE on failure.
Note: The value of the
option does not accept spaces (" ") as delimiters.
The formats of options and longopts are almost the same, the only difference is that longopts needs to be an array of options (each element is an option), while options needs a string (each character is an option).
Parsing of options will terminate at the first non-option found, anything after that will be discarded.