PHP:获取脚本的参数数量
问题描述:
I cannot find (aka: don't have time to read all the manuals
) a way to get the number of arguments passed to a php script.
I have a fixed argument, "id"
and, after that, nothing or a list of dynamic arguments.
I actually handle the case of a not empty list
but I cannot check if the list (after "id"
) is empty because the arguments are dynamic so, unknown.
first case, handled:
php_script.php?id=123&aaa=xxx&bbb=yyy
second case, not handled:
php_script.php?id=456
Is there a way ?
I tried $argv
and $argc
but I get an error.
Notice: Undefined variable: argv in...
答
If you just pass the argument with $_GET variable, you can use:
$num = count($_GET);
Hope this helps