-1

I have a PHP script check.php with a function

<?php
function checkValues($arg1, $arg2){

...

}
?>

How can I pass parameter to the function through the Linux command line and run the script?

2

2 Answers 2

3

When running a script from the command line, all parameters passed in after the file name e.g. php my-script.php 123will be in a PHP array called $argv.

array(2) {
    [0]=> string(13) "my-script.php"
    [1]=> int(3) 123
}
Sign up to request clarification or add additional context in comments.

Comments

2

You need to run PHP:

php /my/script.php arg1 arg2

Then in your PHP file:

<?php
// It's 0 based, but arg1 will be at index 1!
var_dump($argv);

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.