0

i'm making a project in PHP and i have a problem. My problem is that i don't know how to get a variable's name in $_GET foreach loop. My code looks like this:

foreach($_GET as $get) {
   $v_name = //I want to be this variable the $get variable's name
}

So example: if someone make a post request like this: http://www.example.com/?something=example

In this case i want to get the "something".

Thanks everyone who will help me - Jumpak

1 Answers1

-2

You need to print the key of array $_GET

You should read basics of foreach loop.

foreach($_GET as $key=>$get) {
              //  ^^^      // You can get the index key from Array 
    //$v_name = //I want to be this variable the $get variable's name
    echo $key;
}
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
  • 3
    This question should just be flagged as a duplicate. – Nigel Ren Jun 02 '18 at 12:14
  • Thank you, you've solved my problem. :) – Mato Sustak Jun 02 '18 at 12:14
  • @NigelRen already vote to close :) – Muhammad Hassaan Jun 02 '18 at 12:15
  • 2
    why vote to close AND answer? /shrug – James Jun 02 '18 at 12:15
  • OP seems new to site. I think new user don't understand how to it work. I agree there is guide/help but do you really new user will read this carefully? – Muhammad Hassaan Jun 02 '18 at 12:17
  • @MatoSustak mark tick on my answer if you found it useful. – Muhammad Hassaan Jun 02 '18 at 12:21
  • 1
    So you answer a question you know should be closed, and actually voted to close it yourself, and then ask the op for a tick? I guess all you care about is rep, not the quality of the site. – James Jun 02 '18 at 15:52
  • I agree OP seems new. I disagree with what you did because of that. Why not post a comment on his question explaining what dupes are, showing him the dupe, helping him understand it? Now you've shown OP "doesn't matter if you ask a dupe, someone will answer". And in doing so you duplicated answers, which is what duplicates are supposed to avoid :/ – Patrice Jul 03 '18 at 15:46