<? PHP#! /Usr/local/bin/PHP-Q
Echo "test parameters:/N ";
Echo $ _ server ["argc"]. "/N ";
// Display the input parameter value, which starts from Index 1
Echo $ _ server ["argv"] [1]. "/N ";
Echo $ _ server ["argv"] [2]. "/N ";
Echo $ _ server ["argv"] [3]. "/N ";
Echo $ _ server ["argv"] [4]. "/N ";
?>
Copy code
Enter the following code in the command line:
C:/users/John> testargs. php always to be best
Obtain test parameters:
4
Always
To
Be
Best
Because we input a string of words, which are "always to be best", the script parameters are separated by spaces. Therefore, PHP counts it as four parameters, which are described below.
The $ _ server ["argc"] array returns an integer value, which indicates that several parameters are input after you press enter from the command line.
As shown in the preceding example, to access the passed parameter value, you must start with index 1. Because the script file occupies index 0, that is, $ _ server ["argv"] [0]