![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP $argv
Introduction
When a PHP script is run from command line, $argv superglobal array contains arguments passed to it. First element in array $argv[0] is always the name of script. This variable is not available if register_argc_argv directive in php.ini is disabled.
$argv
Following script is executed from command line.
Example
<?php var_dump($argv); ?>
Output
array(1) { [0]=> string(8) "main.php" }
In another example as follows, addition of command line arguments is performed
Example
<?php $add=$argv[1]+$argv[2]; echo "addition = " . $add; ?>
Output
C:\xampp\php>php test1.php 10 20 addition = 30
Advertisements