hisoka Posted March 31, 2016 Share Posted March 31, 2016 Could you please provide me with a simple and clear explanation about what does this mean : $_SERVER["argv"][0] $_SERVER["argv"][1] I read about it here : http://php.net/manual/en/reserved.variables.server.php and here http://php.net/manual/en/reserved.variables.argv.php But I could not understand anything . Link to comment Share on other sites More sharing options...
euc Posted March 31, 2016 Share Posted March 31, 2016 argv is for command line use and not relevant to web pages. It is a list of arguments passed to the script when you type a command into PHP set up like a normal application like a C or Pascal program. $_SERVER["argv"][0] means $_SERVER is a two dimensioanl array. "argv" is the first dimension making it similar to other $_SERVER contents like $_SERVER['PHP_SELF'] but instead of being a single value, it is an array. To access each of the arguments in this array you need the second dimension ie the [0] for the first, [1] for the second and so on. Link to comment Share on other sites More sharing options...
hisoka Posted March 31, 2016 Author Share Posted March 31, 2016 So by using the two dimensional array can I get a list of all commands line or arguments that can be used ?? and if yes how exactly ? I mean I would like to get , for example , the first , second and third command line . Is it done like this : <?php echo $_SERVER["argv"][0]; ?> // first command line echoed <?php echo $_SERVER["argv"][1]; ?> // second command line echoed <?php echo $_SERVER["argv"][2]; ?> // third command line echoed ?? Link to comment Share on other sites More sharing options...
thescientist Posted March 31, 2016 Share Posted March 31, 2016 since it's an array, just use a loop Link to comment Share on other sites More sharing options...
justsomeguy Posted March 31, 2016 Share Posted March 31, 2016 So by using the two dimensional array can I get a list of all commands line or arguments that can be used ??No, it holds the command line arguments that actually were used, not a list of what's available. Link to comment Share on other sites More sharing options...
euc Posted April 1, 2016 Share Posted April 1, 2016 This is only a "I think so" don't quote me although $_SERVER["argv"][0] is certainly a 2 dimensional array and the PHP manual stays "argv Contains an array of all the arguments passed to the script when running from the command line." It is possible to set up PHP to run from the command line you type into your own computer, that is, I think without a separate server for your own use only. I have a server so it's of no use to me and don't know the details. When you type commands into your command interpreter like "copy file1 file2" the two arguments are "file1" and "file2" so if you have PHP setup in this manner $_SERVER["argv"][0] would be 'file1' or it could be 'copy' - like I said "never tried it". $_SERVER["argv"][1] would be 'file2' or it could be 'file1' - ditto $_SERVER["argv"][2] could be 'file2' - ditto Link to comment Share on other sites More sharing options...
hisoka Posted April 1, 2016 Author Share Posted April 1, 2016 " $_SERVER["argv"][0] would be 'file1' or it could be 'copy' - like I said "never tried it". $_SERVER["argv"][1] would be 'file2' or it could be 'file1' - ditto $_SERVER["argv"][2] could be 'file2' - ditto" ARGV is an array containing or holding the values of the arguments passed . "copy" is the command line and file1 , file2 are the arguments passed to it . So argv[0] is file1 argv[1] is file2 and $argc = 2 ; With ARGV there is another called ARGC which is a variable containing or holding the number of arguments passed . So one is an array and the other is a variable . Exciting and interesting . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now