从argv中删除在getopt中找到的选项


Remove options found in getopt from argv

有没有一种快速的方法可以用getopt从$argv中删除找到的选项?

基本上,我有

php trout.php --plugin dozer /opt/webapplications/Word/readme.log

在我的$options=getopt();我有

Array
(
    [plugin] => dozer
)

$argv有以下内容。。。

Array
(
    [0] => --plugin
    [1] => dozer
    [2] => /opt/webapplications/Word/readme.log
)

我想要$argv只有

Array
(
    [0] => /opt/webapplications/Word/readme.log
)

我知道有array_shift可以弹出第一个数组元素,我过去也见过循环,只需通过$argv弹出所有元素,然而,我想知道是否有一种快速简单的方法可以用原生php来完成这一点。。。

这就是我最终使用的原因

function __construct($args) {
    $this->options = getopt($this->shortopts, $this->longopts);
    array_shift($args);
    while(count($args) > 1) {
        if (strpos($args[0], '-') !== false && strpos($args[0], '-') == 0) {
            array_shift($args);
            if(in_array($args[0], $this->options)) {
                array_shift($args);
            }
        }
        else {
            break;
        }
    }
    $this->args = $args;
}