
Wikis & learning
Generate a command-line status line
A command-line script can take an optional argument and still provide a useful default. The first element of argv is the script name.
A command-line script can take an optional argument and still provide a useful default. The first element of argv is the script name.
How it works
Place the file in a working directory and run php status.php catalog. Omit the optional argument to use the fallback.
PHP example
<?php
$section = $argv[1] ?? 'general';
echo 'Checking ' . $section . PHP_EOL;Expected result
Checking catalog when the argument is catalog.
Try a variation
Run the script again with no arguments. Expect the word general.
Discussion
Sign in to participate.



