douzuizhuo0587
2015-02-19 22:20
采纳率: 0%
浏览 41
已采纳

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...
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doumei8258 2015-02-19 22:23
    已采纳

    Use count

    $arg_num = count($_GET);
    
    已采纳该答案
    打赏 评论
  • douli2876 2015-02-19 22:26

    If you just pass the argument with $_GET variable, you can use:

    $num = count($_GET);
    

    Hope this helps

    打赏 评论

相关推荐 更多相似问题