0

I understand that PHP's $argv returns an array with parameters provided at the command line.

I was wondering if there is a function to retrieve the value assigned to a parameter or not. For example:

php mybatch.php --xxx=3

Such function f($argv,"xxx") would return 3. Or do I have to implement it myself?

1 Answer 1

1

The function getopt offers a bit more details and features when dealing with command-line parameters: You want to pass a long parameter, so this will do:

<?php
$opts = getopt(null, ['xxx:']);

if (isset($opts['xxx'])) {
    echo 'Parameter xxx: ' . $opts['xxx'];
}

Result:

Parameter xxx: 3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.