How to Read Program Arguments in PHP Posted in Polyglotbits on 04 of Aug, 2015

In PHP the program arguments of current script is always available in the $argv variable except when it is not.

This means we can easily write the old hello world app as:

if(count($argv)<2) {
  echo "usage: php $argv[0] name [name] [name] [name]";
foreach($argv as $index=>$arg) {
  // skip index zero as this is the script name
  if($index==0) continue;
  echo "Hello $arg\n";