dpv50040
dpv50040
2014-07-22 13:02
浏览 38
已采纳

获取GET方法变量的名称

I have about 5 variables in GET method. They almost always have different names, encoded mostly. How i can get name (not value) of those variables.

example:

$_GET['orchid'] = red;
$_GET['xyc'] = wrack;

and after that, next time i open the page:

$_GET['rose'] = red;
$_GET['gzuy'] = bottle;

Values are not important for now, in this case I need names of variables: "orchid", "xyc" or in second case "rose" and "gzuy".

图片转代码服务由CSDN问答提供 功能建议

我在GET方法中有大约5个变量。 他们几乎总是有不同的名字,主要编码。 我如何获得这些变量的名称(而不是值)。

示例:

  $ _ GET ['orchid'] = red;  
 $ _GET ['xyc'] = wrack; 
   
 
 

之后,下次打开页面时:

  $ _ GET ['rose'] = red; 
 $ _GET ['gzuy'] =瓶子; 
   
 
 

现在值不重要, 在这种情况下,我需要变量名称:“orchid”,“xyc”或第二种情况“rose”和“gzuy”。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • duancoubeng5909
    duancoubeng5909 2014-07-22 13:05
    已采纳
    array_keys($_GET)
    

    For more informations, see the link bellow:

    http://php.net/manual/function.array-keys.php

    点赞 评论
  • donglu9898
    donglu9898 2014-07-22 13:04
       foreach ($_GET as $key=>$value){
        echo $key;
    
       }
    
    点赞 评论
  • dongpin6941
    dongpin6941 2014-07-22 13:04
    foreach ($_GET as $key => $value) {
        //Line below is optional to get around empty values.
        if (!empty($value))
        echo $key, '  ';
    }
    

    The above code will print out all of the set $_GET variables, having file.php?moo will mark moo as set but with a value of nothing. The below snippet will simply return an array just containing the names of the $_GET variables which can then be used in $_GET[$keys[0]] for example to recall its value.

    array_keys($_GET);
    

    Docs:

    foreach loop array_keys()

    点赞 评论
  • douwaif22244
    douwaif22244 2014-07-22 13:04

    array_keys() should do the trick:

    $keys = array_keys($_GET);
    
    点赞 评论

相关推荐