是否可以从命令行传递关键字参数? [重复]

This question already has an answer here:

I want to pass keyword argument to a php script via command line. Something like this:

php some_script.php --arg1 val1 --arg2 val2

How should I do to accomplish this? Is it possible? Or there is a common practice to do it? Thank you very much.

</div>

In PHP there is an array of parameters pre-defined:

php script.php val1 val2

You can access your arguments over

$argv

http://php.net/manual/de/reserved.variables.argv.php

<?php
    // $argv[0] is 'path_to_script.php'
    $arg1= $argv[1];
    $arg2= $argv[2];
?>