- 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 $argc
Introduction
This superglobal variable is available when a PHP script is run from command line (and not when executed from HTTP server's document root). It is an integer that corresponds to number of command line arguments passed to current script. As script's filename has to be entered in command line, minimumn value of $argc is 1. This variable is not available if register_argc_argv directive in php.ini is disabled.
$argc
Following script is expected to be run from command line with 3 arguments including name of script
Example
<?php if ($argc!=3){ echo "invalid number of arguments"; die(); } else{ echo "number of arguments is valid"; } ?>
Output
This script is run with invalid number of arguments
C:\xampp\php>php test1.php 1 2 3 invalid number of arguments
This script is run with valid number of arguments
C:\xampp\php>php test1.php 1 2 number of arguments is valid
Advertisements