PHP obtains the number and list of parameters.

Source: Internet
Author: User
<? 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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.