<?php
$args_raw = $_SERVER['argv'];
$args = array();
$args_num = array();
while (count($args_raw) > 0) {
$a = array_shift($args_raw);
$a = trim($a);
if ($a{0} == '-') {
$b = array_shift($args_raw);
$b = trim($b);
if ($b{0} == '-') {
array_unshift($args_raw, $b);
$b = '';
}
$a = trim($a, '-');
$args[$a] = $b;
} else {
$args_num[] = $a;
}
}
if ($args) {
echo "Matched arguments:\n";
print_r($args);
}
if ($args_num) {
echo "Matched numeric arguments:\n";
print_r($args_num);
}