Skip to content

Examples

Command lines, and the arrays that the parser returns for them.

php test.php -az value1 -abc value2
[
    'a' => 'value2',
    'z' => 'value1',
    'b' => 'value2',
    'c' => 'value2',
]

php test.php -a value1 -abc value2
[
    'a'  => 'value2',
    'b'  => 'value2',
    'c'  => 'value2',
]

php test.php --az value1 --abc value2
[
    'az'  => 'value1',
    'abc' => 'value2',
]

php test.php --foo --bar=baz --spam eggs
[
    'foo'  => true,
    'bar'  => 'baz',
    'spam' => 'eggs',
]

php test.php -abc foo
[
    'a' => 'foo',
    'b' => 'foo',
    'c' => 'foo',
]

php test.php arg1 arg2 arg3
[
    0 => 'arg1',
    1 => 'arg2',
    2 => 'arg3',
]

php test.php \
    plain-arg \
    --foo \
    --bar=baz \
    --funny="spam=eggs" \
    --also-funny=spam=eggs \
    'plain arg 2' \
    -abc \
    -k=value \
    "plain arg 3" \
    --s="original" \
    --s='overwrite' \
    --s
[
    0            => 'plain-arg',
    'foo'        => true,
    'bar'        => 'baz',
    'funny'      => 'spam=eggs',
    'also-funny' => 'spam=eggs',
    1            => 'plain arg 2',
    'a'          => true,
    'b'          => true,
    'c'          => true,
    'k'          => 'value',
    2            => 'plain arg 3',
    's'          => 'overwrite',
]
Navigation

Type to search…

↑↓ navigate↵ selectEsc close