can we use isset() function on $argv[1] in php ,

Viewed 28

can we use isset() function on $argv[1] in php, so that if input is not during script execution then $a can take empty value otherwise it takes input provided. I have written this code below wanted to know if we can do this ?

$a = isset($argv[1])?$argv[1]:"";
1 Answers

It depend on your array because if you want to check [1] then your array length must have to 2 otherwise it will through an error.

$a = $argv[1] ?? ""; // you can use it for not showing any error is your array is empty
Related