How to use variable inside parameter $_GET? example: ($_GET[$my_var])

后端 未结 4 970
太阳男子
太阳男子 2021-01-26 07:23

I\'m developing a plugin for wordpress, the parameter of the $ _GET is recorded in the database according to the preference of the User via the Wordpress Admin Panel. The follow

相关标签:
4条回答
  • 2021-01-26 07:50

    foreach($_GET as $key => $value){ if($key == "nosupport"){

    } }

    0 讨论(0)
  • 2021-01-26 07:53

    You forgot to take out the ' in the second condition.

    You wrote:

         $_GET['$url_before']
    

    I'm guessing it should be:

         $_GET[$url_before]
    
    0 讨论(0)
  • 2021-01-26 07:54

    I found the problem, i had already tested all of these options, but ever dont working, the problem was that I was testing the function inside the main page of my site, and on the main page (mysite.com) does not get the parameter (?page=nossuport), so always returning null values​​, when I used the variable in the GET or used the echo $GET[$my_var] to test.. It was a great carelessness of mine, would never work...

    by the way, the two parameters works correctly:

    $_GET[$url_before]
    $_GET["$url_before"]
    

    The Problem are solved, Thanks for help.

    0 讨论(0)
  • 2021-01-26 07:56
    if($_GET[$url_before] != ""){ 
        if($_GET[$url_before]=="nosupport"){ // note no "" here
            // my function goes here...
        }
    }
    

    In your solution, the key was treated as a string, with no variables evaluated.

    0 讨论(0)
提交回复
热议问题