Command Line Arguments in PHP

Advertisement

Advertisement

In PHP, all command line arguments, including the script name itself are stored in a special array named $argv. The first element, zero, is the name of the script being run. For example:

<?php
echo "This script being executed is named " . $argv[0] . ".\n";

If you run

php myScript.php

The output will be

This script being executed is named test.php.

The output will be the same if you begin the file with a shebang like #!/usr/bin/php and run the script by typing

./myScript.php

All subsequent arguments will be in the $argv array.

Advertisement

Advertisement