Parameters are handled by PHP through the use of two predefined global variables $argc and $argv representing the number of parameters and their values as shown below:
Assuming the following command line:
CODE
$ ./myscript.php param1 param2
...And the PHP script being executed:
CODE
<?php
print "The total parameters count was: $argc\n";
print "The parameters were: ";
foreach ($argv as $val){
print "$val ";
}
print "\n";
?>
The following output will be produced:
CODE
$ ./myscript.php param1 param2
The total parameters count was: 2
The parameters were: myscript.php param1 param2
As you can see, the $argc parameter is an integer representing the total number of parameters passed on the command line. However, notice that the second variable $argv has an extra value! To assist the developer, the first value of the $argv array will be the name of the script executed followed by any command line parameters. Note that regardless of the presence of command line parameters, $argv will always contain the name of the script file being executed.
-------------------------------------------------------------
You can use a foreach:
CODE
foreach ($argv as $option)
{
switch ($option)
{
case 'one':
echo '1';
break;
case 'two':
echo '2';
break;
}
echo "\t";
}