[PHP] Read a positional command-line argument

Created on November 30, 2026

When PHP runs a script from the command line, $argv contains the script name followed by its arguments. Index 1 is the first argument. Save this code as command_line_arguments.php.

<?php

echo $argv[1] . ' is the first command-line argument.' . PHP_EOL;
php command_line_arguments.php hello
hello is the first command-line argument.
PHP