url - Check what parameters are set in a concise way - PHP -


i need many parameters url different names , check if set. (their value doesn't matter).

https://example.com?one=true&two=true&three=true      etc. 

the problem in want do, of them set or not.

so need of way grab of them in url , set in clean way, , preferably stored in different variables matching name of parameters, instead of having multiple $_get , isset() lines if statements on place.

edit: submit being parameter in url: thinking done using foreach loop.

if (isset($_get['submit'])) {   foreach ($_get $key => $value) {   $key = $value;   echo $key;  } } 

this echo out value of $key, (which need because know set), need actual name of $key set to.

thanks

edit 2: have found out how - needed parameters in url , know name of them. sorry if had worded wierdly.

if (isset($_get['submit'])) {  foreach ($_get $key => $value) {  $$value = $key;  echo $key;  } } 

i found out using variable variables needed (hence 2 $$) gives me, in end, $key name of whatever parameters in url, stored in $value has same name.

you need use extract() extract keys array , treat them variables

import variables current symbol table array

here small example:

$_get['var_1'] = 1; $_get['var_2'] = 2; $_get['var_3'] = ''; extract($_get); echo $var_1; 

use below code empty set keys/values:

$newarray = array_filter($_get); $sub_key    = array_keys($newarray); print_r($sub_key); // give keys have values  $sub_values = array_values($newarray); print_r(array_diff($_get, $sub_values)); // keys have empty values 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -