Using Arguments in Scripts
As you all know we can use arguments with PHP (remember world.php was an argument to the PHP interpreter), similarly we can use arguments in our scripts. Wondering how? Lets look at it.
All the arguments passed to your script are stored in a zero based global array variable $argv, also there is one more global variable $argc which holds number of arguments passed to the script (hey all you people coming from C/C++ background this should be familiar to you). Please note: $argc will always be one or more than one as the script name is always the first argument. Here is the code which shall display the total number of argument passed and also will display the arguments
<?
echo "Total argument passed are : $argc n";
for( $i = 0 ; $i <= $argc -1 ;$i++)
{
echo "Argument $i : $argv[$i] n";
}
?>
Assuming this is stored in a file argument.php you could test this script by running something like this
php argument.php arg1 arg2