title: php's command line option parsing, howto
body: <p>I'm using Console_Getopt in PHP 5.2, and finding it surprising about how different it is from getopt in  other languages (perl, bash, java). Can anyone recommend how to parse the args from the array "$opts" returned?</p>
  
  <p>php myprog.php -a varA -c -b varB</p>
  
  <pre><code>$o= new Console_Getopt;
  $opts = $o-&gt;getopt($argv, "a:b:c");
  print_r($opts);
  </code></pre>
  
  <p>// the print_r returns below</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [0] =&gt; a
                      [1] =&gt; varA
                  )
  
              [1] =&gt; Array
                  (
                      [0] =&gt; c
                      [1] =&gt;
                  )
  
              [2] =&gt; Array
                  (
                      [0] =&gt; b
                      [1] =&gt; varB
                  )
  
          )
  
      [1] =&gt; Array
          (
          )
  
  )
  </code></pre>
  
  <p>I started doing something like below, which is long-winded, so I'm looking for suggestions on dealing with command-line flags in php.</p>
  
  <pre><code>foreach($opts[0] as $i -&gt; $keyval) {
      list($key, $val) = $keyval;
      if($key == 'a') {
          print "valueForA: $val\n";
      } else if($key == 'b') {
          print "valueForB: $val\n";         
      } else if($key == 'c') {
          print "c is set\n";
      }
  }
  </code></pre>
  
  <p>I wonder why PHP's getopt isn't like perl's, where the array's key is the flag eg $opts{'a'} .. that would be convenient.</p>